When I tried to debug the stream in the code below via Stream Trace in IntelliJ, the debugger can't evaluate the foreach because the error below is thrown. I have no idea what it's about, the code by itself runs fine.
Fully updated IntelliJ community edition, JUnit 5, Spring Boot, Maven, Java 11.
The error that happens during Stream Trace debugging only:
java.lang.IncompatibleClassChangeError: Type com.progonkpa.file.FileService$GeneratedEvaluationClass$5 is not a nest member of com.progonkpa.file.FileService: types are in different packages
The code that contains the stream:
public class FileService {
public void createDirs(File parentDir, String[] fileNames) {
Stream.of(fileNames)
.map(fileName -> new File(parentDir, fileName))
.forEach(file -> {
if (file.mkdirs())
System.out.println("Created file: " + file);
else
System.err.println("Failed to create file: " + file);
});
}
}
The test that invokes the method above:
public class FileServiceTest {
private FileService fileService = new FileService();
@Test
public void generateDirs_createsList() {
File tmpDir = new File("/tmp");
String[] dirNamesList = {"dir1", "dir2"};
File createdDir1 = new File(tmpDir, dirNamesList[0]);
File createdDir2 = new File(tmpDir, dirNamesList[1]);
fileService.createDirs(tmpDir, dirNamesList);
assertTrue(createdDir1.exists());
assertTrue(createdDir2.exists());
assertTrue(createdDir1.delete());
assertTrue(createdDir2.delete());
assertTrue(tmpDir.delete());
}
}
pom.xml
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.unknown.somefunction</groupId>
<artifactId>joske</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<!--<dependency>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-starter-test</artifactId>-->
<!--<scope>test</scope>-->
<!--</dependency>-->
<!--Data processing-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>simple-java-mail</artifactId>
<version>5.1.3</version>
</dependency>
<dependency>
<groupId>org.simplejavamail</groupId>
<artifactId>outlook-message-parser</artifactId>
<version>1.1.17</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.github.vatbub</groupId>
<artifactId>mslinks</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
<!--Testing-->
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

The Stream debugger apparently generates bytecode and defines classes on the fly to evaluate expressions. Relevant source files are
CompilingEvaluator.java
CompilingEvaluatorImpl.java
And there is a currently opened issue on YouTrack, with the exact same exception
Type some.Type$GeneratedEvaluationClass$1 is not a nest member of some.Type: types are in different packages
IDEA-204665
This manifests itself only on JDK versions greater than 10, and unfortunately you have
<java.version>11</java.version>
As the Issue suggest, it happens because
JDK 11 has "Nest-based Access Control" feature
(https://cr.openjdk.java.net/~dlsmith/nestmates.html)
The JEP 181 says
Impact on Other Tools
Any tool that operates on classfiles, or which generates or processes bytecodes is potentially impacted by these changes. At a minimum such tools must tolerate the presence of the new classfile attributes and allow for the change in bytecode rules. For example:
The javap classfile inspection tool, The Pack200 implementation, and The ASM bytecode manipulation framework, which is also used internally in the JDK.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With