krasa / krasa-jaxb-tools

XJC / JAXB plugin for generation of Bean Validation Annotations (JSR-303) and replacing primitive types
Apache License 2.0
61 stars 47 forks source link

Plugin throws RTE on XReplacePrimitives for serialVersionUID #49

Closed AJGHM-Khonraad closed 3 years ago

AJGHM-Khonraad commented 8 years ago

Using an xjc binding

<jxb:globalBindings>
   <jxb:serializable uid="1"/>  
</jxb:globalBindings>

(i.e. with a uid attribute defined) generates the code

private final static long serialVersionUID = 1L;

-XReplacePrimitives then tries to replace that field and the (non existent) getter and setter and this results in an RTE.

The following patch fixes that:

diff --git a/src/main/java/com/sun/tools/xjc/addon/krasa/PrimitiveFixerPlugin.java b/src/main/java/com/sun/tools/xjc/addon/krasa/PrimitiveFixerPlugin.java
index aea005c..bff1911 100644
--- a/src/main/java/com/sun/tools/xjc/addon/krasa/PrimitiveFixerPlugin.java
+++ b/src/main/java/com/sun/tools/xjc/addon/krasa/PrimitiveFixerPlugin.java
@@ -43,6 +43,15 @@
             for (Map.Entry<String, JFieldVar> stringJFieldVarEntry : fields.entrySet()) {
                 JFieldVar fieldVar = stringJFieldVarEntry.getValue();
                 JType type = fieldVar.type();
+                
+                /*
+                 * Exclude "serialVersionUID" from processing XReplacePrimitives as this will 
+                 * have no getter or setter defined.
+                 */
+                if ("serialVersionUID".equals(fieldVar.name())) {
+                   continue;
+                }
+                    
                 if (type.isPrimitive()) {
                     Class o = hashMap.get(type.name());
                     if (o != null) {
krasa commented 8 years ago

Feel free to make a pull request.

krasa commented 3 years ago

Fixed by #55