Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij IDEA - Evaluate expression with stream API cause error

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()
like image 273
Vyacheslav Tsivina Avatar asked Jan 12 '18 19:01

Vyacheslav Tsivina


People also ask

How do I enable evaluate expressions in Intellij?

Evaluate a complex expression in the editor Click Run | Debugging Actions | Quick Evaluate Expression Ctrl+Alt+F8 . Alternatively, hold Alt and click the selection.

How do I debug a stream in Intellij?

Run your application with the debugger ⌃D (macOS), or Shift+F9 on Windows and Linux. Again, you can click the run icon over in the gutter on the left on line 21 if you prefer. On the right-hand side of the debug window, click the button called Trace Current Stream Chain.

How do you evaluate lambda expression in Intellij?

Start the IDE, Help | Find Action (Ctrl+Shift+A or Cmd+Shift+A on Mac), type "Switch IDE Boot JDK", press Enter. Start the IDE, use Help | Find Action (Ctrl+Shift+A or Cmd+Shift+A on Mac), type "Switch IDE Boot JDK", press Enter. Switch IDE Boot JDK dialog appears.

How do I monitor threads in Intellij?

You can customize how threads are displayed on the Frames and Threads tabs. It might be helpful when you are working on a multithreaded application and often need to access information about your threads. Right-click anywhere in the Frames or Threads tab and select Customize Threads View.


1 Answers

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.

like image 76
gil.fernandes Avatar answered Oct 07 '22 00:10

gil.fernandes