3

i defined a new class called BigDecimalWithAttrDisplay with the following implementation:

class BigDecimalWithAttrDisplay extends BigDecimal{
    String display;
    BigDecimalWithAttrDisplay(String val){super(val)}
    public String toString(){
        "BigDecimalWithAttrDisplay{val=${super.toString()}, display='$display'}";
    }
}

when trying to run code that use this class i get:

java.lang.IncompatibleClassChangeError: the number of constructors during runtime and compile time for java.math.BigDecimal do not match. Expected 17 but got 18
at groovy.lang.MetaClassImpl.selectConstructorAndTransformArguments(MetaClassImpl.java:1381)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.selectConstructorAndTransformArguments(ScriptBytecodeAdapter.java:234)
at com.e4x.auto.services.checkout.testapi.model.response.BigDecimalWithAttrDisplay.<init>(BigDecimalWithAttrDisplay.groovy:31)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.reflection.CachedConstructor.doConstructorInvoke(CachedConstructor.java:71)
at org.codehaus.groovy.runtime.callsite.ConstructorSite.callConstructor(ConstructorSite.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:194)

what is the problem and how can i fix it?

2
  • Which groovy version are you running?
    – Will
    Jan 23, 2013 at 11:07
  • its hard to tell. it is 1.80 or 1.86
    – Yosefki
    Jan 23, 2013 at 11:23

3 Answers 3

6

Try cleaning your created classes (do a fresh rebuild of your project). You might have artifacts from previous compilations.

Another possibility would be that you use Java 7 and Groovy code compiled with a version lower than 7. Then you might also encounter problems. (See for example: Geb - IncompatibleClassChangeError)

2
  • actually in my environment (using intelliJ) i don't have this problem. it's only happen on my integration servers so the always clean (every compilation start from scratch), and i use java 6
    – Yosefki
    Jan 23, 2013 at 11:25
  • I have this same issue were it works fine locally but not in the dev servers.
    – alltej
    Oct 7, 2020 at 18:41
1

Couldn't reproduce your bug in 2.0.5, but if the problem is the lack of constructors, Groovy has an annotation called @InheritConstructors which might help.

Also take a look at @Delegate. It might be cooler than inheritance.

6
  • this @Delegate is very nice.. but for some reason it doesn't work at all, is it supported when using java and groovy joint compilation?
    – Yosefki
    Jan 23, 2013 at 15:27
  • java: someClass.java:91: cannot find symbol symbol : method intValue() location: class com....BigDecimalWithAttrDisplay (i'm using IntelliJ 12)
    – Yosefki
    Jan 23, 2013 at 15:34
  • I had some problems with @Delegate, but those were 1.7.5 times. Do you think you can upgrade to groovy 2?
    – Will
    Jan 23, 2013 at 18:19
  • sadly no. we are very much afraid of comparability issues and i need to learn more about the risks from moving to groovy 2. maybe its intelliJ or the join-compiler fault because when using pure groovy i don't get this error. this is a cool feature anyway :)
    – Yosefki
    Jan 23, 2013 at 21:18
  • And what about a mixin/category? Or are you guys on typed groovy only?
    – Will
    Jan 24, 2013 at 12:30
0

Add a call to BigDecimal constructor by adding super(val) in your constructor.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.