[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 <aleksei.cherepanov@jetbrains.com>
This commit is contained in:
Aleksei.Cherepanov
2023-01-27 07:26:17 +00:00
committed by Space Team
parent b558382f17
commit 07d369998c
8 changed files with 186 additions and 0 deletions
+12
View File
@@ -350,6 +350,18 @@
<jdk_9_0>${env.JDK_9}</jdk_9_0>
</properties>
</profile>
<profile>
<id>jdk_17_0_new</id>
<activation>
<property>
<name>env.JDK_17_0</name>
</property>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jdk_17_0>${env.JDK_17_0}</jdk_17_0>
</properties>
</profile>
<profile>
<id>sign-artifacts</id>
@@ -173,6 +173,18 @@
<goal>run</goal>
</goals>
</execution>
<execution>
<id>integration-test-java17</id>
<configuration>
<projectsDirectory>src/it/java17</projectsDirectory>
<cloneProjectsTo>${project.build.directory}/it/java17</cloneProjectsTo>
<javaHome>${jdk_17_0}</javaHome>
</configuration>
<goals>
<goal>install</goal>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
@@ -0,0 +1,60 @@
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>test-fileSnapshotMap-overflow-app</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>add-many-source-files-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>add-many-source-files</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>src/main/kotlin</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,3 @@
fun foo(){
println("1")
}
@@ -0,0 +1,37 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>add-many-source-files-plugin</artifactId>
<packaging>maven-plugin</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>add-many-source-files-plugin Maven Mojo</name>
<url>http://maven.apache.org</url>
<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${maven.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
</dependency>
</dependencies>
</project>
@@ -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());
}
}
}
}
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>test-fileSnapshotMap-overflow</artifactId>
<version>1.0-SNAPSHOT</version>
<modules>
<module>myPlugin</module>
<module>app</module>
</modules>
<packaging>pom</packaging>
</project>
@@ -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);
}