Skip to content

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

Description

@lpfeup

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions