Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
package groovy.runtime.metaclass.org.codehaus.groovy.antlr
import groovy.formatter.DefaultTraverser
import java.beans.IntrospectionException
class GroovySourceASTMetaClass extends MetaClassImpl {
public GroovySourceASTMetaClass(MetaClassRegistry mcr, Class clazz) throws IntrospectionException
{ super(mcr, clazz) } // version that exhibits the bug
Object getProperty(final Object object, final String property) {
if (property == "children")
else
{ super.getProperty(object, property) }}
/* version that works
Object getProperty(final Object object, final String property) {
def result = null
if (property == "children")
{ result = new ASTIterator(next:object.firstChild) }else
{ result = super.getProperty(object, property) } return result
}
*/
}
class ASTIterator implements Iterator {
Object next = null
boolean hasNext()
{ return next != null; }Object next()
{ def prevNext = next next = next.nextSibling prevNext }void remove()
{ throw new RuntimeException("Removal of AST nodes is not implemented."); }}
// and here is some script that trips with an exception
GroovyRecognizer parser = null
UnicodeEscapingReader unicodeReader = new UnicodeEscapingReader(new StringReader ("println 'Hello, there!'"), null)
GroovyLexer lexer = new GroovyLexer(unicodeReader)
unicodeReader.setLexer(lexer)
parser = GroovyRecognizer.make(lexer)
parser.compilationUnit()
GroovySourceAST ast = (GroovySourceAST) parser.getAST()
ast.children.each
// exception thrown is
// Note: execution is not that of the snippet above.
/*
Exception in thread "main" java.lang.VerifyError: (class: groovy/runtime/metaclass/org/codehaus/groovy/antlr/GroovySourceASTMetaClass, method: getProperty signature: (Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object Inconsistent stack height 1 != 0
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:164)
at groovy.lang.MetaClassRegistry.getMetaClassFor(MetaClassRegistry.java:218)
at groovy.lang.MetaClassRegistry.getMetaClass(MetaClassRegistry.java:142)
at org.codehaus.groovy.runtime.Invoker.getProperty(Invoker.java:247)
at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:213)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getProperty(ScriptBytecodeAdapter.java:501)
at groovy.formatter.GroovySourceFormatter.format(GroovySourceFormatter.groovy:44)
at gjdk.groovy.formatter.GroovySourceFormatter_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:659)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:377)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:344)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:134)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnCurrentN(ScriptBytecodeAdapter.java:89)
at groovy.formatter.GroovySourceFormatter$_run_closure2.doCall(GroovySourceFormatter.groovy:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.codehaus.groovy.runtime.ReflectionMetaMethod.invoke(ReflectionMetaMethod.java:67)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:659)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:377)
at groovy.lang.Closure.call(Closure.java:176)
at groovy.lang.Closure.call(Closure.java:189)
at org.codehaus.groovy.runtime.DefaultGroovyMethods.each(DefaultGroovyMethods.java:677)
at gjdk.java.util.Collection_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
at org.codehaus.groovy.runtime.NewInstanceMetaMethod.invoke(NewInstanceMetaMethod.java:99)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:659)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:377)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:122)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:165)
at groovy.formatter.GroovySourceFormatter.run(GroovySourceFormatter.groovy:28)
at gjdk.groovy.formatter.GroovySourceFormatter_GroovyReflector.invoke(Unknown Source)
at groovy.lang.MetaMethod.invoke(MetaMethod.java:111)
at org.codehaus.groovy.runtime.MetaClassHelper.doMethodInvoke(MetaClassHelper.java:659)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:377)
at org.codehaus.groovy.runtime.Invoker.invokeMethod(Invoker.java:134)
at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:111)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodN(ScriptBytecodeAdapter.java:165)
at groovy.formatter.GroovySourceFormatter.main(GroovySourceFormatter.groovy:12)
*/
Attachments
Issue Links
- duplicates
-
GROOVY-1539 java.lang.VerifyError
- Closed