功能代码上的调试流跟踪抛出 IncompleteClassChangeError

pro*_*kpa 3 java junit stream intellij-idea

当我尝试通过 IntelliJ 中的 Stream Trace 调试下面代码中的流时,调试器无法评估 foreach,因为抛出了下面的错误。我不知道它是什么,代码本身运行良好。

全面更新的 IntelliJ 社区版、JUnit 5、Spring Boot、Maven、Java 11。

仅在 Stream Trace 调试期间发生的错误:

java.lang.InknownClassChangeError:类型 com.progonkpa.file.FileService$GenerateEvaluationClass$5 不是 com.progonkpa.file.FileService 的嵌套成员:类型位于不同的包中

包含流的代码:

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);
                });
    }
}
Run Code Online (Sandbox Code Playgroud)

调用上述方法的测试:

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());
    }
}
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

IntelliJ 社区版中的流跟踪

Lpp*_*Edd 6

流调试器显然会生成字节码并动态定义类来计算表达式。相关源文件有

CompilingEvaluator.java
CompilingEvaluatorImpl.java

YouTrack 上当前有一个未解决的问题,但有完全相同的例外

Type some.Type$GeneratedEvaluationClass$1 is not a nest member of some.Type: types are in different packages
Run Code Online (Sandbox Code Playgroud)

IDEA-204665

这仅在大于 10 的 JDK 版本上表现出来,不幸的是,您有

<java.version>11</java.version>
Run Code Online (Sandbox Code Playgroud)

正如问题所表明的那样,发生这种情况是因为

JDK 11 具有“基于 Nest 的访问控制”功能
https://cr.openjdk.java.net/~dlsmith/nestmates.html

JEP 181

对其他工具的影响

任何操作类文件或生成或处理字节码的工具都可能受到这些更改的影响。至少,此类工具必须容忍新类文件属性的存在,并允许字节码规则的更改。例如:

javap 类文件检查工具、Pack200 实现和 ASM 字节码操作框架(也在 JDK 内部使用)。