- fixed possible NPE when entering DnaQuality data
authorPatric Plitzner <p.plitzner@bgbm.org>
Mon, 27 Oct 2014 10:50:11 +0000 (10:50 +0000)
committerPatric Plitzner <p.plitzner@bgbm.org>
Mon, 27 Oct 2014 10:50:11 +0000 (10:50 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/NumberWithLabelElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/dna/DnaQualityDetailElement.java

index e5f21b4deb11fce9d0aa3be249f39b03becc9248..83e229bd4272bfeab55ed24bfa02f51964cc156c 100644 (file)
@@ -57,35 +57,47 @@ public class NumberWithLabelElement extends TextWithLabelElement {
        }
 
        /**
-        * <p>getInteger</p>
-        *
-        * @return a {@link java.lang.Integer} object.
+        * Get the value of this field as an {@link Integer}.
+        * @return the Integer value or null if {@link NumberFormatException} occurs.
         */
        public Integer getInteger() {
                String text = super.getText().trim();
-               return text.equals("") ? 0 : new Integer(text);
+               try {
+                   return text.equals("") ? 0 : new Integer(text);
+        } catch (NumberFormatException e) {
+            exception = e;
+        }
+               return null;
        }
 
        /**
-        * <p>getFloat</p>
-        *
-        * @return a {@link java.lang.Float} object.
+        * Get the value of this field as a {@link Float}.
+        * @return the Float value or null if {@link NumberFormatException} occurs.
         */
        public Float getFloat(){
-               String text = super.getText();
-               return new Float(text);
+           String text = super.getText();
+           try {
+               return new Float(text);
+           } catch (NumberFormatException e) {
+               exception = e;
+           }
+           return null;
        }
 
        /**
-        * <p>getDouble</p>
-        *
-        * @return a {@link java.lang.Float} object.
+        * Get the value of this field as an {@link Double}.
+        * @return the Double value or null if {@link NumberFormatException} occurs.
         */
        public Double getDouble(){
-               String text = super.getText();
-               return new Double(text);
+           String text = super.getText();
+           try {
+               return new Double(text);
+           } catch (NumberFormatException e) {
+               exception = e;
+           }
+           return null;
        }
-       
+
        private String getStringRepresentation(Object number){
                if(number != null){
                        return number.toString();
@@ -107,15 +119,16 @@ public class NumberWithLabelElement extends TextWithLabelElement {
 
                try{
 
-                       Float number = Float.parseFloat(value);
+                       Float number = Float.parseFloat(value);
 
                        if((start != null && number < start) || (end != null && number > end)){
-                               throw new NumberFormatException("You entered a number that is not within the allowed bounds.");
+                               exception = new NumberFormatException("You entered a number that is not within the allowed bounds.");
+                               throw exception;
                        }
 
                }catch(NumberFormatException e){
                        text.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
-                       firePropertyChangeEvent(new CdmPropertyChangeEvent(this, e));
+                       firePropertyChangeEvent(new CdmPropertyChangeEvent(this, event));
                        exception = e;
                        return;
                }
index ec75ddf55e0a554e98f5cfb4dd0e8b7dbc0d66ce..039f2f745c00364d16aab23fcaad5a05bf2634a6 100644 (file)
@@ -59,6 +59,7 @@ public class DnaQualityDetailElement extends AbstractCdmDetailElement<DnaSample>
         DnaQuality dnaQuality = entity.getDnaQuality();
         if(dnaQuality==null){
             dnaQuality = DnaQuality.NewInstance();
+            entity.setDnaQuality(dnaQuality);
         }
         Double ratioOfAbsorbance260_230 = dnaQuality.getRatioOfAbsorbance260_230();
         Double ratioOfAbsorbance260_280 = dnaQuality.getRatioOfAbsorbance260_280();