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

Bug in valueOf #29

Open
yuemingl opened this issue Apr 14, 2015 · 2 comments
Open

Bug in valueOf #29

yuemingl opened this issue Apr 14, 2015 · 2 comments
Assignees

Comments

@yuemingl
Copy link

I tried this simple test case:

package symjava.test;
public class TestValueOf {
    public static class Car {
        public int id;
        public Car(int id) {
            this.id = id;
        }
        public Car add(Car c) {
            return new Car(this.id+c.id);
        }
    }
    public static class Jeep extends Car {
        public Jeep(int id) {
            super(id);
        }
        public static Jeep valueOf(Car c) {
            return new Jeep(c.id);
        }
    }
    public static void main(String[] args) {
        Car c1 = new Car(1);
        Car c2 = new Car(10);
        Car c12 = c1 + c2;
        //Jeep j = c12; //works
        //Jeep j = Jeep.valueOf(c1 + c2); //works
        Jeep j = c1 + c2; //NOT work!!!
        System.out.println(j.id);
    }
}

An exception is thrown out:

Exception in thread "main" java.lang.VerifyError: Operand stack underflow
Exception Details:
Location:
symjava/test/TestValueOf.main([Ljava/lang/String;)V @25: invokestatic
Reason:
Attempt to pop empty stack.
Current Frame:
bci: @25
flags: { }
locals: { '[Ljava/lang/String;', 'symjava/test/TestValueOf$Car', 'symjava/test/TestValueOf$Car', 'symjava/test/TestValueOf$Car' }
stack: { }
Bytecode:
0000000: bb00 1059 04b7 0012 4cbb 0010 5910 0ab7
0000010: 0012 4d2b 2cb6 0015 4eb8 0019 3a04 b200
0000020: 1f19 04b4 0025 b600 29b1

at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2615)
at java.lang.Class.getMethod0(Class.java:2856)
at java.lang.Class.getMethod(Class.java:1668)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
@msteinbeck
Copy link

I can compile and run your example with both, IntelliJ and javac. Are you using Eclipse? Is this bug already fixed?

@amelentev amelentev added this to the eclipse-oo-0.6 milestone Feb 1, 2016
@amelentev amelentev self-assigned this Feb 1, 2016
@masl123
Copy link

masl123 commented Sep 20, 2016

Another Workaround for this problem is, to simply add a cast. (Jeep j = (Car)(c1 + c2)). This works for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants