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/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..eddabd2 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index f663e52..af4f53b 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Dec 20 21:03:16 MSK 2025 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..249efbb 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,10 +15,12 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # -# Gradle start up script for POSIX generated by Gradle. +# gradlew start up script for POSIX generated by Gradle. # # Important for running: # @@ -27,7 +29,7 @@ # bash, then to run this script, type that shell name before the whole # command line, like: # -# ksh Gradle +# ksh gradlew # # Busybox and similar reduced shells will NOT work, because this script # requires all of these POSIX shell features: @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,22 +132,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -165,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f..8508ef6 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,19 +13,22 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem -@rem Gradle startup script for Windows +@rem gradlew startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,15 +43,15 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% @@ -56,34 +59,24 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 -:mainEnd -if "%OS%"=="Windows_NT" endlocal +@rem Execute gradlew +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel -:omega +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% 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.*" } }