gpt4 book ai didi

java - 功能代码上的调试流跟踪抛出 IncompatibleClassChangeError

转载 作者:行者123 更新时间:2023-11-30 06:41:31 34 4
gpt4 key购买 nike

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

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

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

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

包含流的代码:

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);
});
}
}

调用上述方法的测试:

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>

Stream Trace in IntelliJ Community Edition

最佳答案

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

CompilingEvaluator.java
CompilingEvaluatorImpl.java

目前在 YouTrack 上有一个 Unresolved 问题,但有完全相同的异常(exception)情况

Type some.Type$GeneratedEvaluationClass$1 is not a nest member of some.Type: types are in different packages

IDEA-204665

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

<java.version>11</java.version>

正如问题所暗示的那样,它发生是因为

JDK 11 has "Nest-based Access Control" feature
(https://cr.openjdk.java.net/~dlsmith/nestmates.html)

JEP 181

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.

关于java - 功能代码上的调试流跟踪抛出 IncompatibleClassChangeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55314726/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com