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

Throwable.addSuppressed() called by extension, causing IllegalArgumentException #3138

Closed
moocat opened this issue Jun 6, 2023 · 5 comments · Fixed by eclipse-jdtls/eclipse.jdt.ls#2689
Assignees
Labels
Milestone

Comments

@moocat
Copy link

moocat commented Jun 6, 2023

The extension is calling java.base/java.lang.Throwable.addSuppressed() on all thrown exceptions when in a try (resource) catch block, causing it to throw an IllegalArgumentException, as you cannot use addSuppressed() on yourself.
This then results in the try-catch block not catching its defined exceptions.

This does not seem to be the case on version 1.18.0 of the extension.
Also when compiled and run through the command line, it does not happen.

Environment
  • Operating System: Windows 10
  • JDK version: OpenJDK 18.0.2 and OpenJDK 20.0.1
  • Visual Studio Code version: 1.78.2
  • Java extension version: 1.19.0
Steps To Reproduce

Run the code:

public class Test {
	public static class TestClass implements AutoCloseable {
		@Override
		public void close() throws Exception {
		}
	}

	public static class TestException extends Exception {
		public TestException() {
			super("Test");
		}
	}

	public static void main(String[] args) {
		try (TestClass test = new TestClass()) {
			throw new TestException();
		} catch (TestException e) {
			System.out.println("Success");
		} catch (Exception e) {
			System.out.println("Failure");
			e.printStackTrace();
		}
	}
}
Current Result

Prints:

Failure
java.lang.IllegalArgumentException: Self-suppression not permitted
        at java.base/java.lang.Throwable.addSuppressed(Throwable.java:1071)
        at Test.main(Test.java:17)
Caused by: Test$TestException: Test
        at Test.main(Test.java:16
Expected Result

Should print:

Success
Additional Informations

Running from the command line instead of the extension, will give the desired result:

java Test.java

Prints:

Success
@cygri
Copy link

cygri commented Jun 6, 2023

We are seeing this too with OpenJDK 11.0.18.

@alimoullim91
Copy link

I am getting the same error on openjdk@17 while throwing exception from try-with resource block on macos.

"IllegalArgumentException: Self-suppression not permitted"

The same test when ran with Gradle test produces expected and accurate results.

This is a major bug please fix it ASAP.

@snjeza snjeza self-assigned this Jun 7, 2023
@snjeza snjeza added the upstream label Jun 7, 2023
@snjeza
Copy link
Contributor

snjeza commented Jun 7, 2023

This is an upstream jdt.core issue.
A related issue - eclipse-jdt/eclipse.jdt.core#934

snjeza added a commit to snjeza/eclipse.jdt.ls that referenced this issue Jun 7, 2023
Related issues:
- redhat-developer/vscode-java#3138
- eclipse-jdt/eclipse.jdt.core#934

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
@rgrunber rgrunber added this to the End June 2023 milestone Jun 7, 2023
JessicaJHee pushed a commit to JessicaJHee/eclipse.jdt.ls that referenced this issue Jun 7, 2023
Related issues:
- redhat-developer/vscode-java#3138
- eclipse-jdt/eclipse.jdt.core#934

Signed-off-by: Snjezana Peco <snjezana.peco@redhat.com>
@alimoullim91
Copy link

@snjeza just to let you know this issue still pertains however for my work purposes I have reverted to 1.18 and that works fine for me.

You might want to look into it.

@snjeza
Copy link
Contributor

snjeza commented Jun 8, 2023

@alimoullim91 You can try VS Code Pre-Release

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

Successfully merging a pull request may close this issue.

5 participants