UcasRichard / snakeyaml

Automatically exported from code.google.com/p/snakeyaml
Apache License 2.0
0 stars 0 forks source link

JavaBeanDumper.dump throws NullPointerException on list property with null element #58

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Define a class "Foo" with a list property "bar".
2. Create a new instance of "Foo" and add elements to "bar", including at
least one null value (i.e. 1, "A", null, 3.14).
3. Create a new instance of JavaBeanDumper and invoke dump(), passing the
instance of "Foo" as the argument.

(See attached JUnit test case.)

What is the expected output?
bar:
- 1
- A
- ~
- 3.14

What do you see instead?
java.lang.NullPointerException
    at
org.yaml.snakeyaml.representer.Representer.checkGlobalTag(Representer.java:190)
    at
org.yaml.snakeyaml.representer.Representer.representJavaBeanProperty(Representer
.java:162)
    at
org.yaml.snakeyaml.representer.Representer.representJavaBean(Representer.java:99
)
    at
org.yaml.snakeyaml.representer.Representer$RepresentJavaBean.representData(Repre
senter.java:69)
    at
org.yaml.snakeyaml.representer.BaseRepresenter.representData(BaseRepresenter.jav
a:108)
    at
org.yaml.snakeyaml.representer.BaseRepresenter.represent(BaseRepresenter.java:61
)
    at org.yaml.snakeyaml.Dumper.dump(Dumper.java:52)
    at org.yaml.snakeyaml.JavaBeanDumper.dump(JavaBeanDumper.java:95)
    at org.yaml.snakeyaml.JavaBeanDumper.dump(JavaBeanDumper.java:107)
    at TestJavaBeanDumper.testNullListElement(TestJavaBeanDumper.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at junit.framework.TestCase.runTest(TestCase.java:164)
    at junit.framework.TestCase.runBare(TestCase.java:130)
    at junit.framework.TestResult$1.protect(TestResult.java:106)
    at junit.framework.TestResult.runProtected(TestResult.java:124)
    at junit.framework.TestResult.run(TestResult.java:109)
    at junit.framework.TestCase.run(TestCase.java:120)
    at junit.framework.TestSuite.runTest(TestSuite.java:230)
    at junit.framework.TestSuite.run(TestSuite.java:225)
    at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestR
eference.java:130)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:460)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner
.java:673)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java
:386)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.jav
a:196)

What version of the product are you using?
org.yaml:snakeyaml:1.6

On what operating system?
Ubuntu 9.10 Desktop 64-bit
Linux arcadia 2.6.31-20-generic #58-Ubuntu SMP Fri Mar 12 04:38:19 UTC 2010
x86_64 GNU/Linux

Please provide any additional information below.
Sun Java(TM) SE Runtime Environment (build 1.6.0_15-b03)
JUnit 3.8.2

Original issue reported on code.google.com by jeff.caulfield@gmail.com on 23 Mar 2010 at 5:08

Attachments:

GoogleCodeExporter commented 9 years ago
Fixed. A test helps a lot. Thank you. 
The fix will be available in release 1.7

http://code.google.com/p/snakeyaml/source/detail?r=1cc8fb06f9aac85096af9aa0d9c43
804aad3ca42

Original comment by aso...@gmail.com on 23 Mar 2010 at 6:29

GoogleCodeExporter commented 9 years ago
Glad to be of service.

Original comment by jeff.caulfield@gmail.com on 24 Mar 2010 at 2:24