You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/06/14 02:46:46 UTC
[GitHub] [pulsar] ambition119 opened a new issue #4530: AvroSchema
withAlwaysAllowNull false encode occur SchemaSerializationException:
java.lang.NullPointerException
ambition119 opened a new issue #4530: AvroSchema withAlwaysAllowNull false encode occur SchemaSerializationException: java.lang.NullPointerException
URL: https://github.com/apache/pulsar/issues/4530
**Describe the bug**
```java
public static class Foo {
@Nullable
private String field1;
@Nullable
private String field2;
private int field3;
@Nullable
private Bar field4;
@Nullable
private Color color;
@AvroDefault("\"defaultValue\"")
private String fieldUnableNull;
}
```
this class avro Schema should be:
```
{"type":"record","name":"Foo","namespace":"org.apache.pulsar.client.impl.schema.SchemaTestUtils","fields":[{"name":"field1","type":["null","string"],"default":null},{"name":"field2","type":["null","string"],"default":null},{"name":"field3","type":"int"},{"name":"field4","type":["null",{"type":"record","name":"Bar","fields":[{"name":"field1","type":"boolean"}]}],"default":null},{"name":"color","type":["null",{"type":"enum","name":"Color","symbols":["RED","BLUE"]}],"default":null},{"name":"fieldUnableNull","type":"string","default":"defaultValue"}]}
```
but AvroSchemaTest.testAllowNullEncodeAndDecode avro schema is:
```
{"type":"record","name":"Foo","namespace":"org.apache.pulsar.client.impl.schema.SchemaTestUtils$","fields":[{"name":"field1","type":["null","string"],"default":null},{"name":"field2","type":["null","string"],"default":null},{"name":"field3","type":"int"},{"name":"field4","type":["null",{"type":"record","name":"Bar","fields":[{"name":"field1","type":"boolean"}]}],"default":null},{"name":"color","type":["null",{"type":"enum","name":"Color","symbols":["RED","BLUE"]}],"default":null},{"name":"fieldUnableNull","type":["null","string"],"default":"defaultValue"}]}
```
when fix code like:
```java
AvroSchema<Foo> avroSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).withAlwaysAllowNull(false).build());
```
the exception:
```java
org.apache.pulsar.client.api.SchemaSerializationException: java.lang.NullPointerException: in org.apache.pulsar.client.impl.schema.SchemaTestUtils$.Foo in string null of string in field fieldUnableNull of org.apache.pulsar.client.impl.schema.SchemaTestUtils$.Foo
at org.apache.pulsar.client.impl.schema.writer.AvroWriter.write(AvroWriter.java:48)
at org.apache.pulsar.client.impl.schema.StructSchema.encode(StructSchema.java:81)
at org.apache.pulsar.client.impl.schema.AvroSchemaTest.testAllowNullEncodeAndDecode(AvroSchemaTest.java:231)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
```
**To Reproduce**
Steps to reproduce the behavior:
1. fix AvroSchemaTest.testAllowNullEncodeAndDecode code like:
```java
AvroSchema<Foo> avroSchema = AvroSchema.of(SchemaDefinition.<Foo>builder().withPojo(Foo.class).withAlwaysAllowNull(false).build());
```
2. occur exception
**Expected behavior**
no exception happen.
![image](https://user-images.githubusercontent.com/20353043/59480023-97d17700-8e91-11e9-962a-a95e4ee1e8ad.png)
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services