Skip to content

Commit b7a6183

Browse files
committed
Do not swallow exception details in VirtualThreadTest
1 parent 570f587 commit b7a6183

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

org.eclipse.jdt.debug.jdi.tests/tests/org/eclipse/debug/jdi/tests/VirtualThreadTest.java

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.lang.reflect.Method;
2121
import java.nio.charset.StandardCharsets;
2222
import java.nio.file.Files;
23-
import java.util.Arrays;
23+
import java.util.List;
2424
import java.util.Locale;
2525

2626
import javax.tools.DiagnosticCollector;
@@ -84,6 +84,7 @@ protected void setUp() {
8484
compileTestProgram();
8585
} catch (Exception e) {
8686
StringWriter err = new StringWriter();
87+
err.append(e.getMessage());
8788
e.printStackTrace(new PrintWriter(err));
8889
fail("Error in setup: " + err.toString());
8990
}
@@ -118,9 +119,9 @@ private static void compileFiles(String sourceFilePath, String outputPath) throw
118119
if (!outputFolder.exists()) {
119120
Files.createDirectories(outputFolder.toPath());
120121
}
121-
String[] options = new String[] { "--release", "21", "-d", outputFolder.getAbsolutePath(), "-g", "-proc:none" };
122+
List<String> options = List.of("--release", "21", "-d", outputFolder.getAbsolutePath(), "-g", "-proc:none");
122123
final StringWriter output = new StringWriter();
123-
CompilationTask task = compiler.getTask(output, fileManager, diagnosticCollector, Arrays.asList(options), null, javaFileObjects);
124+
CompilationTask task = compiler.getTask(output, fileManager, diagnosticCollector, options, null, javaFileObjects);
124125
boolean result = task.call();
125126
if (!result) {
126127
throw new IllegalArgumentException("Compilation failed:\n'" + output + "', compiler name: '" + compiler.name()
@@ -164,36 +165,26 @@ public void testJDIThreadEvents() {
164165

165166
/**
166167
* Test restricting JDI ThreadStartEvent/ThreadDeathEvent to platform threads only
168+
*
169+
* @throws Exception
167170
*/
168-
public void testJDIPlatformThreadsOnlyFilter() {
171+
public void testJDIPlatformThreadsOnlyFilter() throws Exception {
169172
// Make sure the entire VM is not suspended before we start a new thread
170173
// (otherwise this new thread will start suspended and we will never get the
171174
// ThreadStart event)
172175
fVM.resume();
173176

174177
// Trigger a thread start event
175178
ThreadStartRequest vThreadStartRequest = fVM.eventRequestManager().createThreadStartRequest();
176-
try {
177-
Method method = vThreadStartRequest.getClass().getMethod("addPlatformThreadsOnlyFilter");
178-
method.invoke(vThreadStartRequest);
179-
} catch (NoSuchMethodException | SecurityException e) {
180-
fail("1");
181-
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
182-
fail("2");
183-
}
179+
Method method = vThreadStartRequest.getClass().getMethod("addPlatformThreadsOnlyFilter");
180+
method.invoke(vThreadStartRequest);
184181
ThreadStartEvent startEvent = (ThreadStartEvent) triggerAndWait(vThreadStartRequest, "ThreadStartEvent", true, 3000);
185182
assertNull("3", startEvent);
186183

187184
// Trigger a thread death event
188185
ThreadDeathRequest vThreadDeathRequest = fVM.eventRequestManager().createThreadDeathRequest();
189-
try {
190-
Method method = vThreadDeathRequest.getClass().getMethod("addPlatformThreadsOnlyFilter");
191-
method.invoke(vThreadDeathRequest);
192-
} catch (NoSuchMethodException | SecurityException e) {
193-
fail("4");
194-
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
195-
fail("5");
196-
}
186+
method = vThreadDeathRequest.getClass().getMethod("addPlatformThreadsOnlyFilter");
187+
method.invoke(vThreadDeathRequest);
197188
ThreadDeathEvent deathEvent = (ThreadDeathEvent) triggerAndWait(vThreadDeathRequest, "ThreadDeathEvent", true, 3000);
198189
assertNull("6", deathEvent);
199190
}

0 commit comments

Comments
 (0)