From b7a6183c8e2ccbad327962af4058ec69b0286b1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Mon, 30 Sep 2024 14:42:47 +0300 Subject: [PATCH] Do not swallow exception details in VirtualThreadTest --- .../debug/jdi/tests/VirtualThreadTest.java | 31 +++++++------------ 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/VirtualThreadTest.java b/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/VirtualThreadTest.java index 1ad5879235..287833f36a 100644 --- a/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/VirtualThreadTest.java +++ b/org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/VirtualThreadTest.java @@ -20,7 +20,7 @@ import java.lang.reflect.Method; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import java.util.Arrays; +import java.util.List; import java.util.Locale; import javax.tools.DiagnosticCollector; @@ -84,6 +84,7 @@ protected void setUp() { compileTestProgram(); } catch (Exception e) { StringWriter err = new StringWriter(); + err.append(e.getMessage()); e.printStackTrace(new PrintWriter(err)); fail("Error in setup: " + err.toString()); } @@ -118,9 +119,9 @@ private static void compileFiles(String sourceFilePath, String outputPath) throw if (!outputFolder.exists()) { Files.createDirectories(outputFolder.toPath()); } - String[] options = new String[] { "--release", "21", "-d", outputFolder.getAbsolutePath(), "-g", "-proc:none" }; + List options = List.of("--release", "21", "-d", outputFolder.getAbsolutePath(), "-g", "-proc:none"); final StringWriter output = new StringWriter(); - CompilationTask task = compiler.getTask(output, fileManager, diagnosticCollector, Arrays.asList(options), null, javaFileObjects); + CompilationTask task = compiler.getTask(output, fileManager, diagnosticCollector, options, null, javaFileObjects); boolean result = task.call(); if (!result) { throw new IllegalArgumentException("Compilation failed:\n'" + output + "', compiler name: '" + compiler.name() @@ -164,8 +165,10 @@ public void testJDIThreadEvents() { /** * Test restricting JDI ThreadStartEvent/ThreadDeathEvent to platform threads only + * + * @throws Exception */ - public void testJDIPlatformThreadsOnlyFilter() { + public void testJDIPlatformThreadsOnlyFilter() throws Exception { // Make sure the entire VM is not suspended before we start a new thread // (otherwise this new thread will start suspended and we will never get the // ThreadStart event) @@ -173,27 +176,15 @@ public void testJDIPlatformThreadsOnlyFilter() { // Trigger a thread start event ThreadStartRequest vThreadStartRequest = fVM.eventRequestManager().createThreadStartRequest(); - try { - Method method = vThreadStartRequest.getClass().getMethod("addPlatformThreadsOnlyFilter"); - method.invoke(vThreadStartRequest); - } catch (NoSuchMethodException | SecurityException e) { - fail("1"); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - fail("2"); - } + Method method = vThreadStartRequest.getClass().getMethod("addPlatformThreadsOnlyFilter"); + method.invoke(vThreadStartRequest); ThreadStartEvent startEvent = (ThreadStartEvent) triggerAndWait(vThreadStartRequest, "ThreadStartEvent", true, 3000); assertNull("3", startEvent); // Trigger a thread death event ThreadDeathRequest vThreadDeathRequest = fVM.eventRequestManager().createThreadDeathRequest(); - try { - Method method = vThreadDeathRequest.getClass().getMethod("addPlatformThreadsOnlyFilter"); - method.invoke(vThreadDeathRequest); - } catch (NoSuchMethodException | SecurityException e) { - fail("4"); - } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { - fail("5"); - } + method = vThreadDeathRequest.getClass().getMethod("addPlatformThreadsOnlyFilter"); + method.invoke(vThreadDeathRequest); ThreadDeathEvent deathEvent = (ThreadDeathEvent) triggerAndWait(vThreadDeathRequest, "ThreadDeathEvent", true, 3000); assertNull("6", deathEvent); }