Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VerifyError - Bad type on operand stack #28

Closed
ghost opened this issue May 27, 2015 · 1 comment
Closed

VerifyError - Bad type on operand stack #28

ghost opened this issue May 27, 2015 · 1 comment
Assignees
Labels
Milestone

Comments

@ghost
Copy link

ghost commented May 27, 2015

The first sample works well with version 0.5.6 but the second sample throws exception for the version 0.6.5

package com.ui4j.test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.ClassLoadingStrategy;
import net.bytebuddy.instrumentation.MethodDelegation;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.AllArguments;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.Origin;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.RuntimeType;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.SuperCall;
import net.bytebuddy.instrumentation.method.bytecode.bind.annotation.This;
import net.bytebuddy.matcher.ElementMatchers;

import com.ui4j.webkit.proxy.WebKitProxy;

public class Main {

    public static interface Element {

        Element addClass(String... names);

        Element removeClass(String... name);
    }

    public static class WebKitElement implements Element {

        public WebKitElement() {
        }

        @Override
        public Element addClass(String... names) {
            return this;
        }

        @Override
        public Element removeClass(String... name) {
            return this;
        }
    }

    public static class WebKitInterceptor {

        @RuntimeType
        public static Object execute(@SuperCall Callable<Object> callable,
                                                @This Object that,
                                                @Origin Method method,
                                                @AllArguments Object[] arguments) {
            try {
                return callable.call();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) throws Exception {
        Class<? extends WebKitElement> loaded = new ByteBuddy()
                                .subclass(WebKitElement.class)
                                .method(ElementMatchers.any()
                                                .and(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class))
                                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("getEngine")))))
                                .intercept(MethodDelegation.to(WebKitInterceptor.class))
                                .make()
                                .load(WebKitProxy.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                                .getLoaded();
        Constructor<? extends WebKitElement> constructor = loaded.getConstructor();
        WebKitElement instance = constructor.newInstance();
        instance.addClass("foo", "bar");
    }
}
package com.ui4j.test;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.concurrent.Callable;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
import net.bytebuddy.implementation.MethodDelegation;
import net.bytebuddy.implementation.bind.annotation.AllArguments;
import net.bytebuddy.implementation.bind.annotation.Origin;
import net.bytebuddy.implementation.bind.annotation.RuntimeType;
import net.bytebuddy.implementation.bind.annotation.SuperCall;
import net.bytebuddy.implementation.bind.annotation.This;
import net.bytebuddy.matcher.ElementMatchers;

import com.ui4j.webkit.proxy.WebKitProxy;

public class Main {

    public static interface Element {

        Element addClass(String... names);

        Element removeClass(String... name);
    }

    public static class WebKitElement implements Element {

        public WebKitElement() {
        }

        @Override
        public Element addClass(String... names) {
            return this;
        }

        @Override
        public Element removeClass(String... name) {
            return this;
        }
    }

    public static class WebKitInterceptor {

        @RuntimeType
        public static Object execute(@SuperCall Callable<Object> callable,
                                                @This Object that,
                                                @Origin Method method,
                                                @AllArguments Object[] arguments) {
            try {
                return callable.call();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    public static void main(String[] args) throws Exception {
        Class<? extends WebKitElement> loaded = new ByteBuddy()
                                .subclass(WebKitElement.class)
                                .method(ElementMatchers.any()
                                                .and(ElementMatchers.not(ElementMatchers.isDeclaredBy(Object.class))
                                                .and(ElementMatchers.not(ElementMatchers.nameStartsWith("getEngine")))))
                                .intercept(MethodDelegation.to(WebKitInterceptor.class))
                                .make()
                                .load(WebKitProxy.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
                                .getLoaded();
        Constructor<? extends WebKitElement> constructor = loaded.getConstructor();
        WebKitElement instance = constructor.newInstance();
        instance.addClass("foo", "bar");
    }
}
Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    com/ui4j/test/Main$WebKitElement$ByteBuddy$x3pjoCmV.addClass([Ljava/lang/String;)Lcom/ui4j/test/Main$Element; @6: invokespecial
  Reason:
    Type '[Ljava/lang/String;' (current frame, stack[3]) is not assignable to 'java/lang/String'
  Current Frame:
    bci: @6
    flags: { }
    locals: { 'com/ui4j/test/Main$WebKitElement$ByteBuddy$x3pjoCmV', '[Ljava/lang/String;' }
    stack: { uninitialized 0, uninitialized 0, 'com/ui4j/test/Main$WebKitElement$ByteBuddy$x3pjoCmV', '[Ljava/lang/String;' }
  Bytecode:
    0x0000000: bb00 2059 2a2b b700 212a b200 2404 bd00
    0x0000010: 1559 032b 53b8 001b c000 1db0          

    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
    at java.lang.Class.getConstructor0(Unknown Source)
    at java.lang.Class.getConstructor(Unknown Source)
    at com.ui4j.test.Main.main(Main.java:69)
@raphw raphw added this to the 0.6.6 milestone May 28, 2015
@raphw raphw added the bug label May 28, 2015
@raphw raphw self-assigned this May 28, 2015
@raphw
Copy link
Owner

raphw commented May 28, 2015

I found the bug. Currently, I am releasing a new bug-fix version. It should be synchronized to Maven Central in a couple of hours.

@raphw raphw closed this as completed May 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant