JavierSA commented on PR #3150:
URL: https://github.com/apache/avro/pull/3150#issuecomment-3533670838

   Hi, @opwvhk, @martin-g and @RyanSkraba:
   
   I updated Avro from 1.12.0 to 1.12.1 and found and issue when executing the 
goal `schema` of avro-maven-plugin: Java classes (.java) generated from Avro 
schemas (.avsc) miss some annotations declared in `"javaAnnotation"` properties.
   
   AFAIK, the problem comes from the changes of this PR because 
`SpecificCompiler` validates annotations now 
([`javaAnnotations()`](https://github.com/apache/avro/blob/release-1.12.1/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java#L1038)
 calls the new method 
[`isValidAsAnnotation()`](https://github.com/apache/avro/blob/release-1.12.1/lang/java/compiler/src/main/java/org/apache/avro/compiler/specific/SpecificCompiler.java#L1067)),
 and this validation only allows annotations whose fields are either primitive 
or String. Therefore, annotations with at least a field whose type is a Class, 
an enum value, an annotation or an array are discarded.
   
   For example, with this annotation:
   
   ```java
   public @interface MyAnnotation {
   
       int primitive() default 1;
   
       String text() default "arg1";
   
       Class<?> clazz() default Random.class;
   
       ElementType enumValue() default ElementType.FIELD;
   
       Override annotation() default @Override;
   
       String[] array() default {"arg1", "arg1"};
   
   }
   ```
   
   and this Avro schema:
   
   ```avsc
   {
     ...
     "fields": [
       {
         "name": "primitive",
         "type": "string",
         "javaAnnotation": "my.package.MyAnnotation(primitive = 1)"
       },
       {
         "name": "text",
         "type": "string",
         "javaAnnotation": "my.package.MyAnnotation(text = \"arg1\")"
       },
       {
         "name": "clazz",
         "type": "string",
         "javaAnnotation": "my.package.MyAnnotation(clazz = 
java.util.Random.class)"
       },
       {
         "name": "enumValue",
         "type": "string",
         "javaAnnotation": "my.package.MyAnnotation(enumValue = 
java.lang.annotation.ElementType.FIELD)"
       },
       {
         "name": "annotation",
         "type": "string",
         "javaAnnotation": "my.package.MyAnnotation(annotation = @Override)"
       },
       {
         "name": "array",
         "type": "string",
         "javaAnnotation": "my.package.MyAnnotation(array = {\"arg1\", 
\"arg1\"})"
       }
     ]
   }
   ```
   ✅ the following Java class will be generated with Avro 1.12.0:
   
   ```java
   @org.apache.avro.specific.AvroGenerated
   public class MyClass extends org.apache.avro.specific.SpecificRecordBase 
implements org.apache.avro.specific.SpecificRecord {
     
     [...]
     
     @my.package.MyAnnotation(primitive = 1)
     private java.lang.String primitive;
     @my.package.MyAnnotation(text = "arg1")
     private java.lang.String text;
     @my.package.MyAnnotation(clazz = java.util.Random.class)
     private java.lang.String clazz;
     @my.package.MyAnnotation(enumValue = 
java.lang.annotation.ElementType.FIELD)
     private java.lang.String enumValue;
     @my.package.MyAnnotation(annotation = @Override)
     private java.lang.String annotation;
     @my.package.MyAnnotation(array = {"arg1", "arg1"})
     private java.lang.String array;
   
     [...]
   }
   ```
   
   ❌ and this one with Avro 1.12.1:
   
   ```java
   @org.apache.avro.specific.AvroGenerated
   public class MyClass extends org.apache.avro.specific.SpecificRecordBase 
implements org.apache.avro.specific.SpecificRecord {
     
     [...]
     
     @my.package.MyAnnotation(primitive = 1)
     private java.lang.String primitive;
     @my.package.MyAnnotation(text = "arg1")
     private java.lang.String text;
     private java.lang.String clazz;
     private java.lang.String enumValue;
     private java.lang.String annotation;
     private java.lang.String array;
   
     [...]
   }
   ```
   
   that is, annotations of fields `clazz`, `enumValue`, `annotation` and 
`array` are missing.
   


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to