apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.64k stars 849 forks source link

Inconsistent code analysis #4554

Closed blakemcbride closed 1 year ago

blakemcbride commented 2 years ago

Apache NetBeans version

Apache NetBeans 15 release candidate

What happened

I have an overloaded Java method (multiple methods with the same name but different arguments). Some of them are deprecated. I am using a depreciated method. Sometimes NetBeans flags the arguments wrong because it doesn't see the deprecated method. Other times it works fine. It is inconsistent.

In this case, it is detecting the deprecated method correctly. When I add a blank line elsewhere, all of a sudden, NetBeans no longer sees the deprecated method and marks the code as having errors. Then, if I add a single space on the blank line, NetBeans then discovers the deprecated method and marks the code correct.

Notice how, when it reports the error, it also unmarks the method as deprecated. This hints to me that it no longer sees the deprecated method. Hence the error report.

Interestingly, if I save the file, the error report disappears.

See the attached pictures pic1 pic2 .

How to reproduce

No response

Did this work correctly in an earlier version?

No / Don't know

Operating System

Fedora Linux

JDK

17

Apache NetBeans packaging

Apache NetBeans provided installer

Anything else

No response

Are you willing to submit a pull request?

No

Code of Conduct

Yes

neilcsmith-net commented 2 years ago

Please check running with a supported JDK (eg. Java 11 or higher), and please check the IDE log for any relevant messages when this occurs and share here. Thanks.

blakemcbride commented 2 years ago

My app runs in Java 8. However, I can run NetBeans in Java 11 if necessary. Can NetBeans 15 work in such a configuration?

(Java 8 is supported through 2030.)

My app has nearly 10,000 classes. I fear upgrading it may be a big job.

neilcsmith-net commented 2 years ago

You can set up a JDK 8 platform in Tools / Java Platforms and configure use of that in your project properties.

Running NetBeans on JDK 8 is unsupported as of NetBeans 13.

blakemcbride commented 2 years ago

I don't use the NetBeans build system. I am using a custom build system driven by a simple Ant interface. So, configuring NetBeans to build with Java 8 won't work in my case.

My default JDK for my system is Java 8. Changing the default will accommodate NetBeans but throw off everything else in all of my development projects. I am considering updating all of my projects to Java 17.

Interestingly, if NB won't run under Java 8, I am surprised it even starts up. Hmmm.

neilcsmith-net commented 2 years ago

Depends if your build system ignores JAVA_HOME I guess.

NetBeans will run, with some things disabled, on Java 8. But it isn't officially supported. Hence asking if you can reproduce with a supported JDK.

blakemcbride commented 2 years ago

Not sure how JAVA_HOME would help since my build system and NetBeans would attempt to use the same value.

blakemcbride commented 2 years ago

I ported my app to Java 17. So now, NetBeans and my app are running under Java 17. Same problem. How do I get the log?

lkishalmi commented 2 years ago

Well check for a red bubble at the bottom line on the right side of the main window. It is possible that NetBeans internal Javac parsing gave up on something (unfortunately it can happen). When that happens, the editor will loose the parser information and can behave pretty strange.

neilcsmith-net commented 2 years ago

How do I get the log?

You can use the View / IDE Log menu item. This is also logged to a file inside the userdir, under var/log. You can see the location of your userdir in the About window, and on 15 the exception reporter dialog will show a direct clickable link.

Thank you for confirming the problem still exists with a supported JDK.

Not sure how JAVA_HOME would help since my build system and NetBeans would attempt to use the same value.

Actually, my mistake, looks like the Ant build doesn't set this - using Maven and Gradle, this environment variable is set to the selected platform when executing the child build process. If you're using Ant, make sure you execute your underlying build using the value of the property platform.home.

blakemcbride commented 2 years ago

Log attached. Thanks! messages.log.txt

neilcsmith-net commented 2 years ago

Thanks. This looks suspicious -Djdk.home=/usr Did you use the Linux installer for 15-rc4? Check the value in netbeans.conf and comment it out. This invalid value might still be causing problems.

blakemcbride commented 2 years ago

It would seem to me that if that were wrong, nothing would work.

I used the NetBeans installer (*.sh file) and used the defaults.

Would you like me to do it again with a different value?

Thanks!

blakemcbride commented 2 years ago

Okay. Here is a setup with a better path. messages.log-2.txt

neilcsmith-net commented 2 years ago

It would seem to me that if that were wrong, nothing would work ... Would you like me to do it again with a different value?

That's incorrect - it will mostly work when wrong for some particular values of "wrong". Please try commenting it out in netbeans.conf first - eg. netbeans_jdkhome= -> #netbeans_jdkhome=. In the very unlikely event it doesn't work you can try the value of JAVA_HOME logged at the top of your messages - /usr/lib/jvm/java-17-openjdk-17.0.4.0.8-1.fc36.x86_64.

For some background on this see #4390 The messages about missing classes make me think that the issue may not be fully resolved by that fix. Please at least verify if your issue persists when that wrong value is removed.

I used the NetBeans installer (*.sh file) and used the defaults.

There is currently no planned release of that Linux installer for NetBeans 15, partly because of that issue.

blakemcbride commented 2 years ago

If you see my prior response, you will see that I already corrected the JDK path without any change.

neilcsmith-net commented 2 years ago

According to the shared log you set it to /usr/lib/jvm/java-openjdk, which is neither commenting it out (preferred!) nor the value of Java Home shown at the top of your log files.

Your previous shared log showed this, which is potentially related to the invalid setting -

INFO [org.netbeans.ui.indexing]: Indexing started, time from last indexing 0 ms.
Even though the source level of /home/blake/NetBeansProjects/Stack360Backend/src/java:/home/blake/NetBeansProjects/Stack360Backend/builder is set to: 17, java.util.zip.CRC32C cannot be found on the system module path: 
blakemcbride commented 2 years ago

Okay. I commented out the line. Same problem. Log attached. Thanks. messages.log.3.txt

blakemcbride commented 2 years ago

No red bubble at the bottom.

neilcsmith-net commented 2 years ago

No red bubble at bottom

Does that mean you still have the problem or not?

If not, also try removing the cache folder (location in Help / About window or in your log - /home/blake/.cache/netbeans/15-rc4). That will force things to re-index.

blakemcbride commented 2 years ago

Yes, I still have the problem. It has been unchanged since the beginning. I was simply answering lkishalmi question above.

aplatypus commented 2 years ago

Confirming this problem in Netbeans v14, v13, and v12

I am currently using Netbeans v14 with Zulu Java18 compiler and Gradle 7.2

It may or may not be relevant that Netbeans 14 insists on accessing Gradle 7.4 no matter what I do. Fortunately we use gradlew set on version 7.2 otherwise our builds would not work.

Possibly related: Gradle 7.4 to load projects -- #4585

neilcsmith-net commented 2 years ago

@aplatypus probably not the same cause. Can you try with NetBeans 15? Bunch of Gradle fixes in there.

@blakemcbride please confirm that you've cleared the cache folder (with NetBeans closed)? If still happening, please check the log for other indexing related messages. Thanks!

lkishalmi commented 2 years ago

Java 18 is supported only from Gradle 7.5.

blakemcbride commented 2 years ago

I don't know where the cache folder is. There is no folder labeled cache under ~/.netbeans

aplatypus commented 2 years ago

@blakemcbride ... Look in hte Netbeans about box -- shows user and cache paths.

aplatypus commented 2 years ago

@lkishalmi ... Why is Netbeans tied to some specific Gradle at all?!! The options dialogue at least gives the impression that I can use any iinstalled gradle version Configured.

As to Java 18, The compile and build uses Java 1.8 and Gradle 7.4; there is as I've said no issue there.

Perhaps if Netbeans honoured the Gradle settings, instead of insisting on launching Gradle 7.4; then it would not give spurious code analysis or errors and it proibably would not consume over 15GB or memory with Gradle 7.4. Just a wild crazy idea.

lkishalmi commented 2 years ago

Well, the JDK version the IDE is running on forces NetBeans to use built-in Gradle version. Run NetBeans on Java 11 and it would respect your wrapper defined Gradle version. It's a design limitation from how the Gradle tooling works, cannot be fixed in NetBeans.

neilcsmith-net commented 2 years ago

@blakemcbride yes, the cache folder is listed in the About window. Default location is under ~/.cache/netbeans/ Unfortunately, the indexing cache can get corrupted by the settings you had. We could really do with a cache clear UI, but it's not as easy as it sounds.

@aplatypus let's keep this on the original issue report, thanks.

roberto-cisternino commented 1 year ago

I have a brend new Netbeans 19 and JDK 17 I can't believe the cache is corrupted in two days... "java.util.zip.CRC32C cannot be found on the system module path" The CRC32C class is part of the base module of JDK17... it is weird it cannot be found...

neilcsmith-net commented 1 year ago

@roberto-cisternino check if you have an invalid value for jdk.home as discussed above. If not, open a separate issue, with your log attached.

roberto-cisternino commented 1 year ago

@roberto-cisternino check if you have an invalid value for jdk.home as discussed above. If not, open a separate issue, with your log attached.

While I had jdk17 my project source/target was 11 so I solved by using 17

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.11.0</version>
            <configuration>
                <!--source>11</source-->
                <!--target>11</target-->
                <release>17</release>
            </configuration>
        </plugin>