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

java.lang.VerifyError is being thrown in specific case #42

Open
lpfeup opened this issue May 26, 2019 · 3 comments
Open

java.lang.VerifyError is being thrown in specific case #42

lpfeup opened this issue May 26, 2019 · 3 comments
Labels

Comments

@lpfeup
Copy link

lpfeup commented May 26, 2019

java.lang.VerifyError is being thrown with the following code example:

public class Main2 {
	public static void main(String[] args) throws InterruptedException {
		Async.init();
		
		test()
		.thenRun(() -> System.out.println("DONE"))
		.exceptionally(t -> {t.printStackTrace();return null;});
		
		Thread.sleep(1000);
	}
	
	private static CompletableFuture<TestModel[]> getTestModels() {
		return CompletableFuture.completedFuture(new TestModel[] { new TestModel(1), new TestModel(2) });
	}
	
	private static CompletableFuture<Void> test() {
		TestModel[] testModelArr = await(getTestModels());
		String str = "";

		for (TestModel myModel: testModelArr) {
			str += ":" + await(CompletableFuture.completedFuture(myModel.myInt));
			System.out.println(myModel.myInt.doubleValue());
		}

		System.out.println(str);
		
		return CompletableFuture.completedFuture(null);
	}
	
	private static class TestModel {
		public final Integer myInt;
		
		private TestModel(Integer myInt) {
			this.myInt = myInt;
		}
	}
}

With any of the following changes to the test() method, it no longer throws the error:

  1. removing System.out.println(myModel.myInt.doubleValue());:
private static CompletableFuture<Void> test() {
	TestModel[] testModelArr = await(getTestModels());
	String str = "";

	for (TestModel myModel: testModelArr) {
		str += ":" + await(CompletableFuture.completedFuture(myModel.myInt));
	}

	System.out.println(str);
	
	return CompletableFuture.completedFuture(null);
}
  1. moving up System.out.println(myModel.myInt.doubleValue()); by 1 line:
private static CompletableFuture<Void> test() {
	TestModel[] testModelArr = await(getTestModels());
	String str = "";

	for (TestModel myModel: testModelArr) {
		System.out.println(myModel.myInt.doubleValue());
		str += ":" + await(CompletableFuture.completedFuture(myModel.myInt));
	}

	System.out.println(str);
	
	return CompletableFuture.completedFuture(null);
}
  1. converting testModelArr to list for the for loop:
private static CompletableFuture<Void> test() {
	TestModel[] testModelArr = await(getTestModels());
	String str = "";

	for (TestModel myModel: Arrays.asList(testModelArr)) {
		str += ":" + await(CompletableFuture.completedFuture(myModel.myInt));
		System.out.println(myModel.myInt.doubleValue());
	}

	System.out.println(str);
	
	return CompletableFuture.completedFuture(null);
}

Any idea why this is happening in this specific case?

@lpfeup
Copy link
Author

lpfeup commented May 26, 2019

Full error detail

Exception in thread "main" java.lang.VerifyError: Bad type on operand stack
Exception Details:
  Location:
    main/Main2.async$test(Ljava/util/concurrent/CompletableFuture;[Lmain/Main2$TestModel;Ljava/lang/String;[Lmain/Main2$TestModel;IILjava/lang/Object;Ljava/lang/StringBuilder;ILjava/lang/Object;)Ljava/util/concurrent/CompletableFuture; @181: getfield
  Reason:
    Type 'java/lang/Object' (current frame, stack[1]) is not assignable to 'main/Main2$TestModel'
  Current Frame:
    bci: @181
    flags: { }
    locals: { '[Lmain/Main2$TestModel;', 'java/lang/String', '[Lmain/Main2$TestModel;', integer, integer, 'java/lang/Object' }
    stack: { 'java/io/PrintStream', 'java/lang/Object' }
  Bytecode:
    0x0000000: 1508 aa00 0000 00e9 0000 0000 0000 0002
    0x0000010: 0000 001a 0000 00ce 0000 00d2 b800 7459
    0x0000020: b600 789a 0022 3a06 1906 b800 7db6 0067
    0x0000030: 1906 0101 0103 0301 0111 0001 ba00 8600
    0x0000040: 00b6 0089 b0b6 008d c000 8f4b 1291 4c2a
    0x0000050: 4d2c be3e 0336 0415 041d a200 6a2c 1504
    0x0000060: 323a 05bb 0095 59b7 0096 2bb6 009a 129c
    0x0000070: b600 9a19 05b4 00a0 b800 2759 b600 789a
    0x0000080: 0027 3a07 3a06 1907 b800 7db6 0067 1907
    0x0000090: 2a2b 2c1d 1504 1905 1906 1100 02ba 0086
    0x00000a0: 0000 b600 89b0 b600 8db6 00a3 b600 a74c
    0x00000b0: b200 3719 05b4 00a0 b600 abb6 00ae 8404
    0x00000c0: 01a7 ff96 b200 372b b600 3f01 b800 27b0
    0x00000d0: 2aa7 ff74 1907 2a2b 2c2d 1504 1505 1906
    0x00000e0: 3a05 3604 3e4d 4c4b a7ff bebb 00b5 59b7
    0x00000f0: 00b6 bf
  Stackmap Table:
    full_frame(@28,{Object[#35],Object[#143],Object[#147],Object[#143],Integer,Integer,Object[#4],Object[#149],Integer,Object[#4]},{})
    full_frame(@69,{},{Object[#35]})
    full_frame(@87,{Object[#143],Object[#147],Object[#143],Integer,Integer},{})
    full_frame(@166,{Object[#143],Object[#147],Object[#143],Integer,Integer,Object[#4]},{Object[#149],Object[#35]})
    full_frame(@196,{Object[#143],Object[#147]},{})
    full_frame(@208,{Object[#35],Object[#143],Object[#147],Object[#143],Integer,Integer,Object[#4],Object[#149],Integer,Object[#4]},{})
    full_frame(@212,{Object[#35],Object[#143],Object[#147],Object[#143],Integer,Integer,Object[#4],Object[#149],Integer,Object[#4]},{})
    full_frame(@235,{Object[#35],Object[#143],Object[#147],Object[#143],Integer,Integer,Object[#4],Object[#149],Integer,Object[#4]},{})

        at java.lang.Class.getDeclaredMethods0(Native Method)
        at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
        at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
        at java.lang.Class.getMethod0(Class.java:3018)
        at java.lang.Class.getMethod(Class.java:1784)
        at sun.launcher.LauncherHelper.validateMainClass(LauncherHelper.java:544)
        at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:526)

@lpfeup
Copy link
Author

lpfeup commented May 26, 2019

Could this be related to #29?

@JoeHegarty JoeHegarty added the bug label May 28, 2019
@JoeHegarty
Copy link
Member

Yes, it could be related. There are a couple of cases where the generated bytecode is not correct.
Unfortunately I haven't had a chance to look into them.

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

2 participants