diff --git a/agent/src/main/java/reactor/blockhound/BlockHound.java b/agent/src/main/java/reactor/blockhound/BlockHound.java index ec20b03..6c3ba5d 100644 --- a/agent/src/main/java/reactor/blockhound/BlockHound.java +++ b/agent/src/main/java/reactor/blockhound/BlockHound.java @@ -134,12 +134,6 @@ public TypePool typePool(ClassFileLocator classFileLocator, ClassLoader classLoa public static class Builder { private final Map>> blockingMethods = new HashMap>>() {{ - put("java/lang/Thread", new HashMap>() {{ - put("sleep", singleton("(J)V")); - put("yield", singleton("()V")); - put("onSpinWait", singleton("()V")); - }}); - put("java/lang/Object", new HashMap>() {{ put("wait", singleton("(J)V")); }}); @@ -219,6 +213,23 @@ public static class Builder { put("forkAndExec", singleton("(I[B[B[BI[BI[B[IZ)I")); }}); } + + try { + // Check if Java 19+ + Class.forName("java.lang.WrongThreadException"); + + put("java/lang/Thread", new HashMap>() {{ + put("sleep0", singleton("(J)V")); + put("yield0", singleton("()V")); + put("onSpinWait", singleton("()V")); + }}); + } catch (ClassNotFoundException __) { + put("java/lang/Thread", new HashMap>() {{ + put("sleep", singleton("(J)V")); + put("yield", singleton("()V")); + put("onSpinWait", singleton("()V")); + }}); + } }}; private final Map> allowances = new HashMap>() {{ diff --git a/example/src/test/java/com/example/BlockingDisallowTest.java b/example/src/test/java/com/example/BlockingDisallowTest.java index 1120a58..e5512a0 100644 --- a/example/src/test/java/com/example/BlockingDisallowTest.java +++ b/example/src/test/java/com/example/BlockingDisallowTest.java @@ -58,7 +58,7 @@ public void shouldDisallow() throws InterruptedException { //given the configuration we expect that Thread.yield() is allowed, but Thread.sleep() inside inner() isn't assertThat(boeRef.get()) .isNotNull() - .hasMessage("Blocking call! java.lang.Thread.sleep") + .hasMessageContaining("Blocking call! java.lang.Thread.sleep") .hasStackTraceContaining("at com.example.BlockingDisallowTest$NonBlockingClass.inner") .hasStackTraceContaining("at com.example.BlockingDisallowTest$NonBlockingClass.outer"); } diff --git a/example/src/test/java/com/example/ReactorTest.java b/example/src/test/java/com/example/ReactorTest.java index 7b4b77d..cd91bcf 100644 --- a/example/src/test/java/com/example/ReactorTest.java +++ b/example/src/test/java/com/example/ReactorTest.java @@ -124,14 +124,14 @@ public static Iterable data() { }); }); - tests.put("java.lang.Thread.sleep", () -> { + tests.put("java.lang.Thread." + (version.feature() >= 19 ? "sleep0" : "sleep"), () -> { return Mono.fromCallable(() -> { Thread.sleep(10); return ""; }); }); - tests.put("java.lang.Thread.yield", () -> { + tests.put("java.lang.Thread." + (version.feature() >= 19 ? "yield0" : "yield"), () -> { return Mono.fromCallable(() -> { Thread.yield(); return "";