Issue Details (XML | Word | Printable)

Key: GROOVY-1910
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Jochen Theodorou
Reporter: Marc Palmer
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
groovy

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

Created: 22/May/07 04:35 AM   Updated: 02/Jul/07 06:26 AM
Component/s: None
Affects Version/s: 1.1-beta-1
Fix Version/s: 1.1-beta-2

Time Tracking:
Not Specified

Testcase included: yes


 Description  « Hide
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


 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Jochen Theodorou added a comment - 22/May/07 05:03 AM
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.

Marc Palmer added a comment - 22/May/07 05:37 AM
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?


Marc Palmer added a comment - 22/May/07 05:38 AM
Obviously I don't think this is a Blocker for 1.1 now, but we need error messages improved as much as possible.

Jochen Theodorou added a comment - 22/May/07 05:49 AM
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

Paul King added a comment - 15/Jun/07 08:17 PM
Still important but no longer blocker as per Marc's latest comments

Paul King added a comment - 15/Jun/07 09:09 PM
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


Jochen Theodorou added a comment - 02/Jul/07 06:26 AM
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.