diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 29165bd..efcf548 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -35,7 +35,7 @@ jobs: java-version: 21 - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 + uses: gradle/actions/setup-gradle@v6 - name: Check formatting run: ./gradlew spotlessCheck --no-daemon diff --git a/agent/src/main/java/io/github/vicitori/threading/highlighter/agent/ThreadingHighlighterAgent.java b/agent/src/main/java/io/github/vicitori/threading/highlighter/agent/ThreadingHighlighterAgent.java index 835afd0..429cb9a 100644 --- a/agent/src/main/java/io/github/vicitori/threading/highlighter/agent/ThreadingHighlighterAgent.java +++ b/agent/src/main/java/io/github/vicitori/threading/highlighter/agent/ThreadingHighlighterAgent.java @@ -35,12 +35,23 @@ public static void agentmain(String agentArgs, Instrumentation inst) { install(inst); } + // Byte Buddy refuses class file versions newer than it officially knows (e.g. the + // Java 25 bytecode shipped by the latest JBR) unless experimental mode is enabled. + // Turning it on keeps the agent working on bleeding-edge IDE platforms instead of + // failing every instrumentation with IllegalArgumentException. The literal is + // relocated by the shadow jar together with the rest of net.bytebuddy, so it + // matches the property name Byte Buddy actually reads at runtime. + private static final String BYTE_BUDDY_EXPERIMENTAL_PROPERTY = "net.bytebuddy.experimental"; + private static void install(Instrumentation inst) { if (!INSTALLED.compareAndSet(false, true)) { AgentLog.info("Agent already installed, skipping duplicate initialization"); return; } + // must run before any Byte Buddy class file version probing below + enableByteBuddyExperimentalIfUnset(); + MarkerAdvice.setWriter(new TraceWriter()); AgentBuilder agent = configureAgent(); List markers = Markers.getAll(); @@ -50,6 +61,12 @@ private static void install(Instrumentation inst) { } } + private static void enableByteBuddyExperimentalIfUnset() { + if (System.getProperty(BYTE_BUDDY_EXPERIMENTAL_PROPERTY) == null) { + System.setProperty(BYTE_BUDDY_EXPERIMENTAL_PROPERTY, "true"); + } + } + private static void instrumentMarker(AgentBuilder agent, MarkerInfo marker, Instrumentation inst) { agent.type(ElementMatchers.named(marker.getClassFqn())) .transform((builder, typeDescription, classLoader, module, protectionDomain) -> diff --git a/common/src/main/java/io/github/vicitori/threading/highlighter/common/marker/Markers.java b/common/src/main/java/io/github/vicitori/threading/highlighter/common/marker/Markers.java index 03ad385..0e51b54 100644 --- a/common/src/main/java/io/github/vicitori/threading/highlighter/common/marker/Markers.java +++ b/common/src/main/java/io/github/vicitori/threading/highlighter/common/marker/Markers.java @@ -23,9 +23,16 @@ * recurse into itself or instrument non-assertion code. Extending coverage is a * matter of adding an entry here (the agent, filter, trace format and plugin are * all marker-agnostic). + * + *

Since platform build ~233 the internal calling code increasingly calls + * {@code ThreadingAssertions} directly instead of going through + * {@code ApplicationImpl}. Both classes are instrumented so the agent captures + * markers regardless of which path the platform takes. */ public final class Markers { + // --- ApplicationImpl markers (legacy path, still used by plugin code) --- + public static final MarkerInfo SLOW_OPERATION = new MarkerInfo( "com.intellij.util.SlowOperations", "assertSlowOperationsAreAllowed", @@ -56,7 +63,38 @@ public final class Markers { "Write Access", "This code requires write access and must run inside a write action on the EDT (see Application.runWriteAction())."); - private static final List ALL = List.of(SLOW_OPERATION, NON_EDT, EDT, READ_ACCESS, WRITE_ACCESS); + // --- ThreadingAssertions markers (direct path used by platform internals) --- + + private static final String THREADING_ASSERTIONS_CLASS = + "com.intellij.util.concurrency.ThreadingAssertions"; + + public static final MarkerInfo EDT_DIRECT = new MarkerInfo( + THREADING_ASSERTIONS_CLASS, + "assertEventDispatchThread", + "EDT Thread", + "This code must run on the EDT (Event Dispatch Thread). UI operations are allowed."); + + public static final MarkerInfo NON_EDT_DIRECT = new MarkerInfo( + THREADING_ASSERTIONS_CLASS, + "assertBackgroundThread", + "Non-EDT Thread", + "This code must NOT run on the EDT. Background/pooled thread required."); + + public static final MarkerInfo READ_ACCESS_DIRECT = new MarkerInfo( + THREADING_ASSERTIONS_CLASS, + "assertReadAccess", + "Read Access", + "This code requires read access and must run inside a read action (see Application.runReadAction())."); + + public static final MarkerInfo WRITE_ACCESS_DIRECT = new MarkerInfo( + THREADING_ASSERTIONS_CLASS, + "assertWriteAccess", + "Write Access", + "This code requires write access and must run inside a write action on the EDT (see Application.runWriteAction())."); + + private static final List ALL = List.of( + SLOW_OPERATION, NON_EDT, EDT, READ_ACCESS, WRITE_ACCESS, + EDT_DIRECT, NON_EDT_DIRECT, READ_ACCESS_DIRECT, WRITE_ACCESS_DIRECT); public static List getAll() { return ALL; diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 3e5d78e..3549e58 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -17,8 +17,7 @@ repositories { dependencies { implementation(project(":common")) intellijPlatform { - // Target the local test IDE (IntelliJ IDEA Community 2025.1, build 251) - intellijIdeaCommunity("2025.1.1.1") + intellijIdeaUltimate("2025.3.1") bundledPlugin("org.jetbrains.kotlin") } @@ -35,8 +34,8 @@ dependencies { intellijPlatform { pluginConfiguration { ideaVersion { - sinceBuild = "251" - untilBuild = "251.*" + sinceBuild = "253" + untilBuild = "253.*" } }