groovy

Some property names used in the value of a Map cause IncompatibleClassChangeError

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.1-beta-1
  • Fix Version/s: 1.1-beta-2
  • Component/s: None
  • Labels:
    None
  • Testcase included:
    yes
  • Number of attachments :
    0

Description

This is rather bizarre and took a while to track down. The following code can run in groovy console 1.1 and shows 2 classes, identical other than the name of a property used as a map value. The first fails to load, the second works.

class Test {
	
	// The names of the properties are what cause the problem here
	static HOL_ISTANBUL = "b"

	static RECOMMENDATIONS = [
		"oops": HOL_INSTANBUL
	]

}

// Test loading of the class
try {
  x = new Test()
  println "Test class loaded fine"
} catch (Throwable t) {
  println "Class Test would not load: ${t}"
}

class Test2 {
	
	static CONST_B = "b"

	static RECOMMENDATIONS = [
		"oops": CONST_B
	]

}

// Test loading of the second class
try {
  x = new Test2()
  println "Test2 class loaded fine"
} catch (Throwable t) {
  println "Class Test2 would not load: ${t}"
}

I get the output:

Class Test would not load: java.lang.IncompatibleClassChangeError
Test2 class loaded fine

Activity

Hide
blackdrag blackdrag added a comment -

hmm, yes... HOL_ISTANBUL is not HOL_INSTANBUL. That should give a different exception... like missing property Exception or maybe even a compile time error.

Show
blackdrag blackdrag added a comment - hmm, yes... HOL_ISTANBUL is not HOL_INSTANBUL. That should give a different exception... like missing property Exception or maybe even a compile time error.
Hide
Marc Palmer added a comment -

Yes, sorry my typo. I looked so many times and couldn't see it.

However the error message was a big part of the reason I didn't see it. Can we get this fixed?

Show
Marc Palmer added a comment - Yes, sorry my typo. I looked so many times and couldn't see it. However the error message was a big part of the reason I didn't see it. Can we get this fixed?
Hide
Marc Palmer added a comment -

Obviously I don't think this is a Blocker for 1.1 now, but we need error messages improved as much as possible.

Show
Marc Palmer added a comment - Obviously I don't think this is a Blocker for 1.1 now, but we need error messages improved as much as possible.
Hide
blackdrag blackdrag added a comment -

the error message is from the VM, that's why it is so bad. And yes, of course it can be fixed... the compiler should never produce invalid bytecode

Show
blackdrag blackdrag added a comment - the error message is from the VM, that's why it is so bad. And yes, of course it can be fixed... the compiler should never produce invalid bytecode
Hide
Paul King added a comment -

Still important but no longer blocker as per Marc's latest comments

Show
Paul King added a comment - Still important but no longer blocker as per Marc's latest comments
Hide
Paul King added a comment -

As a holding pattern, there is now a try/catch around the getProperty() call in ScriptBytecodeAdapter.getGroovyObjectProperty() for LinkageErrors. There is a TODO to remove the workaround once the real bug is fixed.

For this case, the error message is now Caught: java.lang.ExceptionInInitializerError and if you print the stack trace:

java.lang.ExceptionInInitializerError
...
Caused by: org.codehaus.groovy.GroovyException: Unable to get property 'HOL_INSTANBUL'
...
Caused by: java.lang.IncompatibleClassChangeError

Show
Paul King added a comment - As a holding pattern, there is now a try/catch around the getProperty() call in ScriptBytecodeAdapter.getGroovyObjectProperty() for LinkageErrors. There is a TODO to remove the workaround once the real bug is fixed. For this case, the error message is now Caught: java.lang.ExceptionInInitializerError and if you print the stack trace: java.lang.ExceptionInInitializerError ... Caused by: org.codehaus.groovy.GroovyException: Unable to get property 'HOL_INSTANBUL' ... Caused by: java.lang.IncompatibleClassChangeError
Hide
blackdrag blackdrag added a comment -

The compiler will now throw an error if you mistype a name while initializing a static property/field. I also removed the workaround Paul added.

Show
blackdrag blackdrag added a comment - The compiler will now throw an error if you mistype a name while initializing a static property/field. I also removed the workaround Paul added.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: