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/12/25 11:39:27 UTC

[GitHub] [pulsar] massakam commented on a change in pull request #5938: Upgrade Avro to 1.9.1

massakam commented on a change in pull request #5938: Upgrade Avro to 1.9.1
URL: https://github.com/apache/pulsar/pull/5938#discussion_r361303017
 
 

 ##########
 File path: pulsar-client/src/main/java/org/apache/pulsar/client/impl/schema/StructSchema.java
 ##########
 @@ -133,14 +135,34 @@ public SchemaInfo getSchemaInfo() {
         if (StringUtils.isNotBlank(schemaDefinition.getJsonDef())) {
             return parseAvroSchema(schemaDefinition.getJsonDef());
         } else if (pojo != null) {
-            return schemaDefinition.getAlwaysAllowNull() ? ReflectData.AllowNull.get().getSchema(pojo) : ReflectData.get().getSchema(pojo);
+            ThreadLocal<Boolean> validateDefaults = null;
+
+            try {
+                Field validateDefaultsField = Schema.class.getDeclaredField("VALIDATE_DEFAULTS");
+                validateDefaultsField.setAccessible(true);
+                validateDefaults = (ThreadLocal<Boolean>) validateDefaultsField.get(null);
+            } catch (NoSuchFieldException | IllegalAccessException e) {
+                throw new RuntimeException("Cannot disable validation of default values", e);
+            }
+
+            final boolean savedValidateDefaults = validateDefaults.get();
+
+            try {
+                // Disable validation of default values for compatibility
+                validateDefaults.set(false);
 
 Review comment:
   I think this is not a very good way. However, there seems to be no public method to disable validation. Another option is to enable validation of default values.

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