From 07d369998cf7405a5edcc58ad6312302d9de7da9 Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Fri, 27 Jan 2023 07:26:17 +0000 Subject: [PATCH] [Maven] Add test for the fix of illegal reflective access while using jdk17 IJ-203 dependency has illegal reflective access usage, which is prohibited without a special flag since JDK17. Specific reflect usage was fixed on the IntelliJ side (IDEA-31024). After the new IC was present in 1.8.0, this problem shows up on modules with a large number of source files in Maven projects. During the incremental compilation, FileSnapshotMap is filled up with paths to files as keys, so in the test, we generate a lot of source files with long names. If there are a lot of files to compile, a key chunk with paths overflowed and drops the current chunk to the disk, after that PersistentHashMap caches FilterOutputStream and uses illegal reflective access. Closing caches after the first IC attempt fix this problem: `63a0660c` IC: Close caches before falling back to non-incremental compile `908dbf32` IC: Clean up closing caches logic in IncrementalCompilerRunner.kt authored by Hung Nguyen This commit should be reverted after the update of IJ dependency (KT-47765) #KT-55709 Fixed Merge-request: KT-MR-8359 Merged-by: Aleksei Cherepanov --- libraries/pom.xml | 12 ++++ .../tools/kotlin-maven-plugin-test/pom.xml | 12 ++++ .../test-fileSnapshotMap-overflow/app/pom.xml | 60 +++++++++++++++++++ .../app/src/main/kotlin/test.kt | 3 + .../myPlugin/pom.xml | 37 ++++++++++++ .../src/main/java/AddManySourceFilesMojo.java | 40 +++++++++++++ .../test-fileSnapshotMap-overflow/pom.xml | 16 +++++ .../test-fileSnapshotMap-overflow/verify.bsh | 6 ++ 8 files changed, 186 insertions(+) create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/pom.xml create mode 100755 libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/src/main/kotlin/test.kt create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/src/main/java/AddManySourceFilesMojo.java create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/pom.xml create mode 100644 libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/verify.bsh diff --git a/libraries/pom.xml b/libraries/pom.xml index 10f79950ab7..28ba5cab2d3 100644 --- a/libraries/pom.xml +++ b/libraries/pom.xml @@ -350,6 +350,18 @@ ${env.JDK_9} + + jdk_17_0_new + + + env.JDK_17_0 + + true + + + ${env.JDK_17_0} + + sign-artifacts diff --git a/libraries/tools/kotlin-maven-plugin-test/pom.xml b/libraries/tools/kotlin-maven-plugin-test/pom.xml index d03dd90f889..e642d60ccee 100644 --- a/libraries/tools/kotlin-maven-plugin-test/pom.xml +++ b/libraries/tools/kotlin-maven-plugin-test/pom.xml @@ -173,6 +173,18 @@ run + + integration-test-java17 + + src/it/java17 + ${project.build.directory}/it/java17 + ${jdk_17_0} + + + install + run + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/pom.xml new file mode 100644 index 00000000000..2342147c1de --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/pom.xml @@ -0,0 +1,60 @@ + + + + 4.0.0 + + org.jetbrains.kotlin + test-fileSnapshotMap-overflow-app + 1.0-SNAPSHOT + + + UTF-8 + true + + + + + org.jetbrains.kotlin + kotlin-stdlib + ${kotlin.version} + + + + + + + org.jetbrains.kotlin + add-many-source-files-plugin + 0.0.1-SNAPSHOT + + + + add-many-source-files + + + + + + + kotlin-maven-plugin + org.jetbrains.kotlin + ${kotlin.version} + + + compile + + compile + + + + src/main/kotlin + + + + + + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/src/main/kotlin/test.kt b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/src/main/kotlin/test.kt new file mode 100755 index 00000000000..b6b1387eb7f --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/app/src/main/kotlin/test.kt @@ -0,0 +1,3 @@ +fun foo(){ + println("1") +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/pom.xml new file mode 100644 index 00000000000..3cb15d60f47 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/pom.xml @@ -0,0 +1,37 @@ + + + 4.0.0 + org.jetbrains.kotlin + add-many-source-files-plugin + maven-plugin + 0.0.1-SNAPSHOT + + add-many-source-files-plugin Maven Mojo + http://maven.apache.org + + + 1.8 + 1.8 + + + + + org.apache.maven + maven-plugin-api + ${maven.version} + + + org.apache.maven.plugin-tools + maven-plugin-annotations + 3.7.0 + provided + + + org.apache.maven + maven-core + ${maven.version} + + + diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/src/main/java/AddManySourceFilesMojo.java b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/src/main/java/AddManySourceFilesMojo.java new file mode 100644 index 00000000000..79fe92f7035 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/myPlugin/src/main/java/AddManySourceFilesMojo.java @@ -0,0 +1,40 @@ +import org.apache.maven.model.Dependency; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; + +import java.io.*; +import java.nio.file.Files; +import java.util.List; + +@Mojo(name = "add-many-source-files", defaultPhase = LifecyclePhase.COMPILE) +public class AddManySourceFilesMojo + extends AbstractMojo { + @Parameter(defaultValue = "${project}", required = true, readonly = true) + public MavenProject project; + + public void execute() + throws MojoExecutionException { + File srcFolder = new File(project.getBasedir().getAbsolutePath(), "src/main/kotlin"); + if (!srcFolder.exists()) { + throw new MojoExecutionException("Src dir is not present"); + } + int numberOfFiles = 500; + for (Integer count = 0; count < numberOfFiles; count++) { + File generatedKtFile = new File(srcFolder, "SmallFileWithBigNameXXXXXXXXXXXXXXXXXXXXXXXXXX" + count.toString() + ".kt"); + try { + String str = "fun foo" + count.toString() + "(){\n" + + " println(\"2\")\n" + + "}"; + BufferedWriter writer = new BufferedWriter(new FileWriter(generatedKtFile)); + writer.write(str); + writer.close(); + } catch (IOException e) { + throw new MojoExecutionException(e.getMessage()); + } + } + } +} diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/pom.xml b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/pom.xml new file mode 100644 index 00000000000..7ac68e0587e --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/pom.xml @@ -0,0 +1,16 @@ + + + 4.0.0 + + org.jetbrains.kotlin + test-fileSnapshotMap-overflow + 1.0-SNAPSHOT + + myPlugin + app + + pom + + \ No newline at end of file diff --git a/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/verify.bsh b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/verify.bsh new file mode 100644 index 00000000000..fa3b82934c1 --- /dev/null +++ b/libraries/tools/kotlin-maven-plugin-test/src/it/java17/test-fileSnapshotMap-overflow/verify.bsh @@ -0,0 +1,6 @@ +import java.io.*; + +File file = new File(basedir, "app/target/test-fileSnapshotMap-overflow-app-1.0-SNAPSHOT.jar"); +if (!file.exists() || !file.isFile()) { + throw new FileNotFoundException("Could not find generated JAR: " + file); +}