Когда я попытался отладить поток в приведенном ниже коде через Stream Trace в IntelliJ, отладчик не может оценить foreach, потому что выдается ошибка, показанная ниже. Понятия не имею, о чем речь, сам по себе код работает нормально.
Полностью обновленная версия сообщества IntelliJ, JUnit 5, Spring Boot, Maven, Java 11.
Ошибка, возникающая только во время отладки Stream Trace:
java.lang.IncompatibleClassChangeError: Type
com.progonkpa.file.FileService $ GeneratedEvaluationClass $ 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);
});
}
}
Тест, который вызывает метод выше:
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>