Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.5, 2.3.6, 2.3.7
-
None
-
None
-
Java: Oracle 1.8.0_20
Linux: Ubuntu 14.04
Description
Given: Two groovy classes that uses @AutoClone and loaded in order shown below:
AutoCloneBug.groovy
import groovy.transform.AutoClone @AutoClone class B { String name='B' } @AutoClone class A { B b String name='A' } public static void main(String ... args) { B b = new B().clone() //Works A a1 = new A(b:b).clone() //Null Pointer Exception A a2 = new A().clone() }
When: I run this program using Groovy 2.3.5 - 2.3.7
groovy AutoCloneBug.groovy
Then: It results in Null Pointer Exception.
Caught: java.lang.NullPointerException: Cannot invoke method clone() on null object java.lang.NullPointerException: Cannot invoke method clone() on null object at com.meltmedia.cdp.orch.B$clone.call(Unknown Source) at com.meltmedia.cdp.orch.A.clone(AutoCloneBug.groovy) at com.meltmedia.cdp.orch.A$clone.call(Unknown Source) at AutoCloneBug.run(AutoCloneBug.groovy:25)
Note:
The issue seems to be in
https://github.com/groovy/groovy-core/blob/GROOVY_2_3_7/src/main/org/codehaus/groovy/transform/AutoCloneASTTransformation.java#L241
We possibly need to check for null using ifS .
Also if we reverse the order of A and B, the issue goes away. Possible because AutoClone transformation thinks at that point that B does not implement Cloneable .