Intellij IDEA - Evaluate expression with stream API cause error

Vyacheslav Tsivina :

I'm struggling with evaluation expression that contains some Stream API methods. Example:

sample.reads.stream().filter(s -> s.l.length() < 10)

This doesn't work as well:

sample.reads.stream().filter(s -> s.l.length() < 10).collect(Collectors.toList())

gives:

enter image description here

However, sample.reads.stream().count() or sample.reads.stream().toArray() works fine as well as any other expression(and if I put stream API call into code it also works fine)

Config: Java: jdk1.8.0_144

Idea: IntelliJ IDEA 2017.3.1 (Community Edition) Build #IC-173.3942.27, built on December 11, 2017 JRE: 1.8.0_152-release-1024-b8 amd64 JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o Windows 10 10.0

UPDATE

Sorry, for confusion. Even terminal commands don't work. I showed this example because I found that examption is thrown on filter method, not on collect. If I add .collect() I'll see the same error

UPDATE 2 I don't think it's something with classes. Even this gives me the same error:

IntStream.range(0, 100).filter(i -> i%2 == 0).toArray()
gil.fernandes :

This is a bit of a guess, but the problem seems to be a classpath related problem. Due to this you get the message that specific packages cannot be found.

I do not think this is due to terminal or non terminal stream operations. Even non terminal operations can be evaluated in IDEA without errors. See this:

enter image description here

I strongly suggest to check the Run/Debug configuration in IDEA and check which classpath is being used for this application. Open the following dialog and check what is in the "Use classpath of module" field:

enter image description here

A wrong value might have sneaked in there.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=443092&siteId=1