Skip to main content



      Home
Home » Language IDEs » Java Development Tools (JDT) » Weird invalid Java error(built in Java methods are marked as undefined)
Weird invalid Java error [message #1859703] Thu, 22 June 2023 18:28 Go to next message
Eclipse UserFriend
Recently, some of our code suddenly started reporting errors. Code that hasn't changed in a long time.

Example: This line of code:
return new ArrayList<>(otherComponents.stream().filter(aComponent::isCutAndStack).toList());

Is getting this error:
The method toList() is undefined for the type Stream<aComponent>

I've cleaned all projects, exited eclipse, cleaned all projects, and it's still happening. I've also rebooted and cleaned again. There are 7 different lines of code that use toList() that are getting this error. We use toList() 115 times total.


Any suggestions on how to fix this?
Re: Weird invalid Java error [message #1859705 is a reply to message #1859703] Thu, 22 June 2023 19:09 Go to previous messageGo to next message
Eclipse UserFriend
Are you compiling against the JRE you think you are? toList() was only added in Java 16. If you recently changed from only having a Java 17 runtime in your workspace to adding a genuine Java 11 runtime, it could lead to this.
Re: Weird invalid Java error [message #1859706 is a reply to message #1859705] Thu, 22 June 2023 19:22 Go to previous messageGo to next message
Eclipse UserFriend
My Eclipse only has a Java 17 VM defined.
Also, wouldn't the other hundred plus occurrences also have failed when I did a full clean build?
Re: Weird invalid Java error [message #1859711 is a reply to message #1859706] Fri, 23 June 2023 01:39 Go to previous messageGo to next message
Eclipse UserFriend
If you use Ctrl-Shift-T and search for java.util.Stream, does it really only find the one instance defined in a Java 16 or higher JRE?
Re: Weird invalid Java error [message #1859721 is a reply to message #1859711] Fri, 23 June 2023 04:05 Go to previous messageGo to next message
Eclipse UserFriend
This indeed looks odd. As Nitin and Ed suggested, it seems like something related to the JRE you're compiling against.
Just to ensure, are all projects in your workspace configured to use the Java 17 VM? You can check this in the 'Java Build Path' of your project settings.
Also, do the error-marked 'toList()' calls belong to a particular project or a specific set of files? That might give us a clue too.
Lastly, try using Ctrl-Shift-T as Ed suggested to see if there's more than one 'java.util.Stream' in your classpath.
Re: Weird invalid Java error [message #1859734 is a reply to message #1859721] Fri, 23 June 2023 12:23 Go to previous messageGo to next message
Eclipse UserFriend
Ok, now it's getting REALLY REALLY annoying.
I pulled the latest code and started Eclipse this morning. (the 1 line of code change was NOT in any of the relevant files.)
Eclipse came up, refreshed - and the error was gone.

I've been having Eclipse complaining about perfectly valid code, clean, shutdown, clean - and the problem is gone, happening at least once a week.
This is the first time it took being shutdown overnight to fix it.
Note that my system did NOT reboot last night.

Also, note that I did a ctrl-shift-T, and while "Stream" is defined by several different jars, there was only 1 from a JVM. (17)
I'm starting to wonder if all this is related to the "Eclipse can't guess/find the import" issue that I've seen. (and I see has been mentioned by other people.)
Re: Weird invalid Java error [message #1859759 is a reply to message #1859734] Mon, 26 June 2023 03:33 Go to previous message
Eclipse UserFriend
It's strange that a simple restart (especially after an overnight shutdown) would clear the error. This makes me suspect that there could be an issue with the Eclipse workspace's internal state getting corrupt, leading to these bizarre errors.

Here are a few things you might want to try:

1. Try running Eclipse with the '-clean' command line argument. This instructs Eclipse to clean its cached data used for quick startup, among other things.

2. You might want to try creating a new workspace and importing your projects into it. I know it's a bit of a hassle, but it could help if the issue is related to workspace corruption.

3. Check if there are any updates available for Eclipse that might address this issue. They usually fix such problems in new versions.

Regarding the "Eclipse can't guess/find the import" issue, it could be related, but without more specific details, it's hard to say for sure.
Previous Topic:[SOLVED] Changing unreachable code behavior
Next Topic:Derby Client JDBC Driver Connection Failure
Goto Forum:
  


Current Time: Fri May 23 13:38:16 EDT 2025

Powered by FUDForum. Page generated in 0.07775 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top