cbuschka / beanshell2

Automatically exported from code.google.com/p/beanshell2
0 stars 0 forks source link

java.lang.VerifyError: (class: BshTestExtended, method: _bshSuperexecute signature: (J)J) Register 1 contains wrong type #104

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
When trying to override a Method of a Superclass with long, float or double 
argument i will get following Exception:

Exception in thread "main" java.lang.VerifyError: (class: BshTestExtended, 
method: _bshSuperexecute signature: (J)J) Register 1 contains wrong type
    at java.lang.Class.getDeclaredFields0(Native Method)
    at java.lang.Class.privateGetDeclaredFields(Class.java:2436)
    at java.lang.Class.getField0(Class.java:2761)
    at java.lang.Class.getField(Class.java:1577)
    at bsh.Reflect.findAccessibleField(Reflect.java:338)
    at bsh.Reflect.resolveExpectedJavaField(Reflect.java:296)
    at bsh.Reflect.getLHSStaticField(Reflect.java:220)
    at bsh.ClassGenerator.generateClassImpl(ClassGenerator.java:129)
    at bsh.ClassGenerator.generateClass(ClassGenerator.java:29)
    at bsh.BSHClassDeclaration.generateClass(BSHClassDeclaration.java:97)
    at bsh.BSHClassDeclaration.eval(BSHClassDeclaration.java:63)
    at bsh.Interpreter.eval(Interpreter.java:672)
    at bsh.Interpreter.eval(Interpreter.java:747)
    at BshTest.main(BshTest.java:62)

Example:
Java Class:
public class BshTest
{

    public int execute( int job )
    {
        System.out.print( "org: " );
        return 0;
    }

    public long execute( long job )
    {
        System.out.print( "org: " );
        return 0;
    }

    public float execute( float job )
    {
        System.out.print( "org: " );
        return 0;
    }

    public double execute( double job )
    {
        System.out.print( "org: " );
        return 0;
    }

}

Bsh: 

class BshTestExtended extends BshTest
{
    public short execute( short job )
    {
        System.out.print( "bsh: " );
        return 1;
    }

    public int execute( int job )
    {
        System.out.print( "bsh: " );
        return 1;
    }

    public long execute( long job )
    {
        System.out.print( "bsh: " );
        return 1;
    }

    public float execute( float job )
    {
        System.out.print( "bsh: " );
        return 1;
    }

    public double execute( double job )
    {
        System.out.print( "bsh: " );
        return 1;
    }
};

return new BshTestExtended();

I found a Solution:

### Eclipse Workspace Patch 1.0
#P BeanShell
Index: src/bsh/ClassGeneratorUtil.java
===================================================================
--- src/bsh/ClassGeneratorUtil.java (revision 172)
+++ src/bsh/ClassGeneratorUtil.java (working copy)
@@ -584,14 +584,26 @@
        cv.visitVarInsn(ALOAD, 0);
        // Push vars
        int localVarIndex = 1;
-       for (String paramType : paramTypes) {
-           if (isPrimitive(paramType)) {
-               cv.visitVarInsn(ILOAD, localVarIndex);
-           } else {
-               cv.visitVarInsn(ALOAD, localVarIndex);
-           }
-           localVarIndex += ((paramType.equals("D") || paramType.equals("J")) ? 2 : 1);
+       
+       final Type[] types = Type.getArgumentTypes( methodDescriptor );
+       for (Type type : types) 
+       {
+           cv.visitVarInsn( type.getOpcode( ILOAD ), localVarIndex );
+           localVarIndex += type.getSize();
        }
+       
+//     for( String paramType : paramTypes )
+//     {
+//            if (isPrimitive(paramType)) 
+//            {
+//                cv.visitVarInsn(ILOAD, localVarIndex);
+//            } 
+//            else 
+//            {
+//                cv.visitVarInsn(ALOAD, localVarIndex);
+//            }
+//            localVarIndex += ((paramType.equals("D") || 
paramType.equals("J")) ? 2 : 1);
+//     }

        cv.visitMethodInsn(INVOKESPECIAL, superClassName, methodName, methodDescriptor);

Original issue reported on code.google.com by pmne...@googlemail.com on 5 Aug 2014 at 5:28