BZ #90: Groovy console throws java.lang.LinkageError

Status fields:

creation_ts:2008-07-21 09:52
component:verifier
version:default branch
rep_platform:All
op_sys:All
bug_status:RESOLVED
resolution:DUPLICATE
reporter:twisti@complang.tuwien.ac.at
cthalinger@cthalinger:~/projects/groovy/groovy-1.5.6/bin$ java -version
java version "1.6.0_0"
OpenJDK  Runtime Environment (build 1.6.0_0-b10)
CACAO (build 1.1.0pre, JIT mode)
cthalinger@cthalinger:~/projects/groovy/groovy-1.5.6/bin$ ./groovyConsole
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:101)
        at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130)
Caused by: java.lang.LinkageError: subtype constraint violated (java.lang.Object is not
a subclass of java.util.Iterator)
        at
groovy.util.FactoryBuilderSupport.handleNodeAttributes(FactoryBuilderSupport.java:527)
        at groovy.util.FactoryBuilderSupport.createNode(FactoryBuilderSupport.java:358)
        at
groovy.util.FactoryBuilderSupport.doInvokeMethod(FactoryBuilderSupport.java:390)
        at
groovy.util.FactoryBuilderSupport.invokeMethod(FactoryBuilderSupport.java:207)
        at
groovy.util.FactoryInterceptorMetaClass.invokeMethod(FactoryBuilderSupport.java:812)
        at groovy.lang.GroovyObjectSupport.invokeMethod(GroovyObjectSupport.java:44)
        at groovy.lang.Script.invokeMethod(Script.java:78)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(Scri
ptBytecodeAdapter.java:85)
        at groovy.ui.ConsoleActions.run(ConsoleActions.groovy:28)
        at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:677)
        at groovy.util.FactoryBuilderSupport.build(FactoryBuilderSupport.java:665)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:778)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecod
eAdapter.java:170)
        at groovy.ui.Console.run(Console.groovy:162)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:616)
        at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
        at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:230)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:912)
        at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:756)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokePogoMethod(InvokerHelper.java:778)
        at
org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:758)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecod
eAdapter.java:170)
        at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0(ScriptBytecod
eAdapter.java:198)
        at groovy.ui.Console.main(Console.groovy:123)
        ... 6 more

Comment #1 by stefan@complang.tuwien.ac.at on 2008-09-02 20:30:39

The code in question looks like this:

protected void handleNodeAttributes(java.lang.Object, java.util.Map);
  Code:
   0:   aload_1
   1:   ifnonnull       5
   4:   return
   5:   aload_0
   6:   getfield        #36; //Field proxyBuilder:Lgroovy/util/FactoryBuilderSupport;
   9:   getfield        #26; //Field attributeDelegates:Ljava/util/LinkedList;
   12:  invokevirtual   #111; //Method
java/util/LinkedList.iterator:()Ljava/util/Iterator;
   15:  astore_3
   16:  aload_3
   17:  invokeinterface #112,  1; //InterfaceMethod java/util/Iterator.hasNext:()Z
...

This looks very much like #82. However, I don't understand at all why the verifier
chokes on this. java.util.LinkedList.iterator() (pos 12) clearly returns a
java.util.Iterator which is then used for the invokeinterface, so even with the
incorrect understanding of invokeinterface (like in #82), this should work. I'm not very
well versed with Java generics, though. Maybe I'm missing something.

Nonetheless, I flag this as a duplicate.


*** This bug has been marked as a duplicate of bug 82 ***

Comment #2 by twisti@complang.tuwien.ac.at on 2008-09-03 10:05:54

Edwin, could you have a look at this one if it's really a duplicate?

Comment #3 by stefan@complang.tuwien.ac.at on 2008-09-04 15:22:20

For the sake of completeness, this is the entire function.

Method name:"handleNodeAttributes" protected Descriptor:
(java.lang.Object,java.util.Map)void
Attribute "Code", length:181, max_stack:5, max_locals:4, code_length:85
  0: aload_1
  1: ifnonnull 5
  4: return
  5: aload_0
  6: getfield <Field groovy.util.FactoryBuilderSupport.proxyBuilder
groovy.util.FactoryBuilde
rSupport>
  9: getfield <Field groovy.util.FactoryBuilderSupport.attributeDelegates
java.util.LinkedLis
t>
 12: invokevirtual <Method java.util.LinkedList.iterator ()java.util.Iterator>
 15: astore_3
 16: aload_3
 17: invokeinterface <InterfaceMethod java.util.Iterator.hasNext ()boolean> nargs:1
 22: ifeq 57
 25: aload_3
 26: invokeinterface <InterfaceMethod java.util.Iterator.next ()java.lang.Object>
nargs:1
 31: checkcast <Class groovy.lang.Closure>
 34: iconst_3
 35: anewarray <Class java.lang.Object>
 38: dup
 39: iconst_0
 40: aload_0
 41: aastore
 42: dup
 43: iconst_1
 44: aload_1
 45: aastore
 46: dup
 47: iconst_2
 48: aload_2
 49: aastore
 50: invokevirtual <Method groovy.lang.Closure.call
(java.lang.Object[])java.lang.Object>
 53: pop
 54: goto 16
 57: aload_0
 58: getfield <Field groovy.util.FactoryBuilderSupport.proxyBuilder
groovy.util.FactoryBuilderSupport>
 61: invokevirtual <Method groovy.util.FactoryBuilderSupport.getCurrentFactory
()groovy.util.Factory>
 64: aload_0
 65: aload_1
 66: aload_2
 67: invokeinterface <InterfaceMethod groovy.util.Factory.onHandleNodeAttributes
(groovy.util.FactoryBuilderSupport,java.lang.Object,java.util.Map)boolean> nargs:4
 72: ifeq 84
 75: aload_0
 76: getfield <Field groovy.util.FactoryBuilderSupport.proxyBuilder
groovy.util.FactoryBuilderSupport>
 79: aload_1
 80: aload_2
 81: invokevirtual <Method groovy.util.FactoryBuilderSupport.setNodeAttributes
(java.lang.Object,java.util.Map)void>
 84: return
Attribute "LineNumberTable", length:30, count: 7
  line: 519 at pc: 0
  line: 520 at pc: 4
  line: 523 at pc: 5
  line: 524 at pc: 25
  line: 527 at pc: 57
  line: 528 at pc: 75
  line: 530 at pc: 84
Attribute "LocalVariableTable", length:42, count: 4
  slot#3: name: iter, type: java.util.Iterator (pc: 16 length: 41)
  slot#0: name: this, type: groovy.util.FactoryBuilderSupport (pc: 0 length: 85)
  slot#1: name: node, type: java.lang.Object (pc: 0 length: 85)
  slot#2: name: attributes, type: java.util.Map (pc: 0 length: 85)



It's quite strange that it complains about line 527 because the invokeinterface in
position 67 does not have anything to do with java.util.Iterator. The "this" argument
for this invokeinterface is provided by the getCurrentFactory which clearly returns the
correct type.

Comment #4 by stefan@complang.tuwien.ac.at on 2008-09-04 15:23:29

Doesn't look like a duplicate to me...

Comment #5 by edwin.steiner@gmx.net on 2008-09-05 13:59:28

The backtrace is misleading in this case. I set breakpoints and found that
the error actually occurs in this method:

groovy.swing.factory.ActionFactory.onHandleNodeAttributes(Lgroovy/util/FactoryBuilderSup
port;Ljava/lang/Object;Ljava/util/Map;)Z PUBLIC

The code that cannot be verified:

619: invokestatic <Method
org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethod0
(java.lang.Class,java.lang.Object,java.lang.String)java.lang.Object>
622: astore 9
624: aload 9
626: invokeinterface <InterfaceMethod java.util.Iterator.hasNext ()boolean> nargs:1

So I can confirm that this is indeed a duplicate of #82.

Comment #6 by twisti@complang.tuwien.ac.at on 2008-09-05 14:39:45

Thank you Edwin.  Now we only need a fix for this problem :-)

Comment #7 by stefan@complang.tuwien.ac.at on 2009-06-10 11:04:58

*** This bug has been marked as a duplicate of bug 82 ***