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/03/05 09:38:58 UTC

[GitHub] [pulsar] sijie opened a new pull request #3754: NullPointerException at using BytesSchema.of()

sijie opened a new pull request #3754: NullPointerException at using BytesSchema.of()
URL: https://github.com/apache/pulsar/pull/3754
 
 
   Fixes #3734
   
   *Motivation*
   
   Exception occurred when using `BytesSchema.of()`
   
   ```
   Exception in thread "main" java.lang.ExceptionInInitializerError
   	at org.apache.pulsar.examples.simple.ProducerExample.main(ProducerExample.java:32)
   Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
   	at org.apache.pulsar.client.internal.ReflectionUtils.catchExceptions(ReflectionUtils.java:36)
   	at org.apache.pulsar.client.internal.DefaultImplementation.newKeyValueSchema(DefaultImplementation.java:158)
   	at org.apache.pulsar.client.api.Schema.<clinit>(Schema.java:123)
   	... 1 more
   Caused by: java.lang.reflect.InvocationTargetException
   	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
   	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
   	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
   	at org.apache.pulsar.client.internal.DefaultImplementation.lambda$newKeyValueSchema$16(DefaultImplementation.java:160)
   	at org.apache.pulsar.client.internal.ReflectionUtils.catchExceptions(ReflectionUtils.java:34)
   	... 3 more
   Caused by: java.lang.NullPointerException
   	at org.apache.pulsar.client.impl.schema.KeyValueSchema.<init>(KeyValueSchema.java:68)
   	... 9 more
   ```
   
   The problem introduced because the weird class loading and reflection sequence.
   
   When accessing `BytesSchema`, `BytesSchema` will try to initialize `Schema`. When initializing Schema, it will attempts
   to initialize `KV_BYTES` using reflection, and initializing KV_BYTES requires `BytesSchema`. Hence it causes KV_BYTES not being
   initialized correctly.
   
   The change is to avoid this recrusive class loading.
   
   *Modifications*
   
   Make KV_BYTES as a method not a static field in `Schema`.
   
   *Verify this change*
   
   Add a test to reproduce the issue and verify it is fixed.
   
   ### Does this pull request potentially affect one of the following parts:
   
   *If `yes` was chosen, please highlight the changes*
   
     - Dependencies (does it add or upgrade a dependency): (no)
     - The public API: (*yes*) : we changed the type of `Schema#KV_BYTES` from a field to a method.
     - The schema: (*yes*)
     - The default values of configurations: (no)
     - The wire protocol: (no)
     - The rest endpoints: (no)
     - The admin cli options: (no)
     - Anything that affects deployment: (no)
   
   ### Documentation
   
     - Does this pull request introduce a new feature? (no)
     - If yes, how is the feature documented? (not applicable)
     - If a feature is not applicable for documentation, explain why?
     - If a feature is not documented yet in this PR, please create a followup issue for adding the documentation
   

----------------------------------------------------------------
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