NullPointerException occurs when reading a YAML with no value.

57 views
Skip to first unread message

HIRUKAWA Ryo

unread,
Nov 15, 2017, 11:46:26 AM11/15/17
to yamlbeans-users
NullPointerException occurs when reading a YAML with no value in the master branch.

(example)
item:
  name: foo
  price: 100
  description: 

"description" has no value.

Exception in thread "main" java.lang.NullPointerException
at java.lang.Integer.decode(Integer.java:1161)
at com.esotericsoftware.yamlbeans.YamlReader.readValueInternal(YamlReader.java:206)
at com.esotericsoftware.yamlbeans.YamlReader.readValue(YamlReader.java:138)
at com.esotericsoftware.yamlbeans.YamlReader.readValueInternal(YamlReader.java:351)
at com.esotericsoftware.yamlbeans.YamlReader.readValue(YamlReader.java:138)
at com.esotericsoftware.yamlbeans.YamlReader.readValueInternal(YamlReader.java:351)
at com.esotericsoftware.yamlbeans.YamlReader.readValue(YamlReader.java:138)
at com.esotericsoftware.yamlbeans.YamlReader.readValueInternal(YamlReader.java:351)
at com.esotericsoftware.yamlbeans.YamlReader.readValue(YamlReader.java:138)
at com.esotericsoftware.yamlbeans.YamlReader.read(YamlReader.java:105)
at com.esotericsoftware.yamlbeans.YamlReader.read(YamlReader.java:92)
at com.esotericsoftware.yamlbeans.YamlReader.read(YamlReader.java:86)


--- yamlbeans-master\src\com\esotericsoftware\yamlbeans\YamlReader.java 2017-11-08 21:03:59.000000000 +0900
+++ yamlbeans-fixed\src\com\esotericsoftware\yamlbeans\YamlReader.java 2017-11-16 01:38:12.342209100 +0900
@@ -202,17 +202,19 @@
                        case SCALAR:
                                if (config.readConfig.guessNumberTypes) {
                                        String value = ((ScalarEvent)event).value;
-                                       try {
-                                               Integer convertedValue = Integer.decode(value);
-                                               if (anchor != null) anchors.put(anchor, convertedValue);
-                                               return convertedValue;
-                                       } catch (NumberFormatException ex) {
-                                       }
-                                       try {
-                                               Float convertedValue = Float.valueOf(value);
-                                               if (anchor != null) anchors.put(anchor, convertedValue);
-                                               return convertedValue;
-                                       } catch (NumberFormatException ex) {
+                                       if(value != null) {
+                                               try {
+                                                       Integer convertedValue = Integer.decode(value);
+                                                       if (anchor != null) anchors.put(anchor, convertedValue);
+                                                       return convertedValue;
+                                               } catch (NumberFormatException ex) {
+                                               }
+                                               try {
+                                                       Float convertedValue = Float.valueOf(value);
+                                                       if (anchor != null) anchors.put(anchor, convertedValue);
+                                                       return convertedValue;
+                                               } catch (NumberFormatException ex) {
+                                               }
                                        }
                                }
                                type = String.class;

Nate

unread,
Nov 15, 2017, 3:20:35 PM11/15/17
to yamlbea...@googlegroups.com
Fixed, thanks!

--
--
You received this message because you are subscribed to the "yamlbeans-users" group:
http://groups.google.com/group/yamlbeans-users

---
You received this message because you are subscribed to the Google Groups "yamlbeans-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to yamlbeans-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

md wakil

unread,
Jun 7, 2018, 2:32:26 AM6/7/18
to yamlbeans-users
NullPointerException is still coming with tag having no value. Could someone provide fix for the same?
Reply all
Reply to author
Forward
0 new messages