Skip to content

Writing Java in VS CODE shows way too much warnings! #1657

Closed
eclipse-jdtls/eclipse.jdt.ls
#1579

Description

@lakshits11

Java Code in vs code shows way too much warnings. I mean these are really unnecessary warnings ! Even IDEs like IntelliJ don't show these unnecessary warnings. I want to disable such warnings, but not all the warnings. Is there a way to do so, or can you please do something about it ?

Environment
  • Operating System: Windows 10 Pro
  • JDK version:
    java 14.0.2 2020-07-14
    Java(TM) SE Runtime Environment (build 14.0.2+12-46)
    Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
  • Visual Studio Code version: 1.50.1
  • Java extension version: 0.69.0
Steps To Reproduce

Download the folder below and open in vs code

assignmentSix.zip

Here we see that under MonthException we see a squiggle line with warning:

a

Warning Given:
The serializable class MonthException does not declare a static final serialVersionUID field of type longJava(536871008)

Even IDE like IntelliJ dont show these useless warnings...
b

So is there any way to disable these warnings _(NOT ALL WARNINGS)_ I mean can I only select what warnings I want to see and what I don't?

Activity

  1. snjeza commented on Oct 15, 2020

    @snjeza
    Collaborator

    @lakshits11 You can try to add

    org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore
    

    to your your_project/.settings/org.eclipse.jdt.core.prefs

  2. lakshits11 commented on Oct 15, 2020

    @lakshits11
    Author

    I did that but still it is showing me squiggle line under there !

  3. snjeza commented on Oct 15, 2020

    @snjeza
    Collaborator

    The .settings/org.eclipse.jdt.core.prefs file have to be placed to your project directory as follows:

    your_project
      - .project
      - .classpath
    ... your other files...
      - .settings
        - org.eclipse.jdt.core.prefs
    

    Could you attach a project example?

  4. lakshits11 commented on Oct 16, 2020

    @lakshits11
    Author

    Yes, see the image ..
    aa

  5. snjeza commented on Oct 16, 2020

    @snjeza
    Collaborator

    @lakshits11 Could you, please, attach a project example?

  6. lakshits11 commented on Oct 16, 2020

    @lakshits11
    Author

    You mean the zip file of my project ? If I am wrong, please help me to understand.

  7. snjeza commented on Oct 16, 2020

    @snjeza
    Collaborator

    You mean the zip file of my project?

    Right.

  8. lakshits11 commented on Oct 16, 2020

    @lakshits11
    Author
  9. 0dinD commented on Oct 16, 2020

    @0dinD
    Contributor

    @snjeza I have an idea for why the Eclipse preference doesn't seem to be working. It seems that the language server won't recognize any Eclipse preferences under .settings in "invisible projects" or whatever they're called. For me, it works in any normal maven/gradle/eclipse project, but not in a simple "invisible project" like this one. Is there a reason behind this or should it be considered a bug? (And can you confirm?)

    @lakshits11 An alternative way to get rid of warnings is with the @SuppressWarnings annotation:

    package Exceptions;
    
    @SuppressWarnings("serial")
    public class MonthException extends Exception {
    
        public MonthException(String s) {
            super(s);
        }
    
    }

    The annotation is a way to explicitly ignore certain warnings from within your code, which means that even other people working on the same piece of code won't see the error, regardless of their editor settings. FYI the missingSerialVersion warning is not specific to this extension, it's also present in the Eclipse IDE. The drawback with this solution is that you need to write this annotation on every class that will generate the warning, which can be tedious.

    If I'm right about why the Eclipse preference to disable the warning doesn't work, I have another workaround you can try which is to add some files to initialize your project as an Eclipse project instead of an "invisible project". This way, the extension should be able to recognize .settings/org.eclipse.jdt.core.prefs. Try the following:

    Add a file called .project to your root project folder with the following contents:

    <?xml version="1.0" encoding="UTF-8"?>
    <projectDescription>
    	<name>assignmentSix</name>
    	<comment></comment>
    	<projects>
    	</projects>
    	<buildSpec>
    		<buildCommand>
    			<name>org.eclipse.jdt.core.javabuilder</name>
    			<arguments>
    			</arguments>
    		</buildCommand>
    	</buildSpec>
    	<natures>
    		<nature>org.eclipse.jdt.core.javanature</nature>
    	</natures>
    </projectDescription>
    

    Also add a file called .classpath to your root project folder with the following contents:

    <?xml version="1.0" encoding="UTF-8"?>
    <classpath>
    	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    	<classpathentry kind="src" path="src"/>
    	<classpathentry kind="output" path="bin"/>
    </classpath>
    

    Finally, after adding these two files, you should also restart VS Code. Did it work?

  10. snjeza commented on Oct 16, 2020

    @snjeza
    Collaborator

    If I'm right about why the Eclipse preference to disable the warning doesn't work,

    @0dinD You are right. We should link the .settings directory to an "invisible project" too.

  11. lakshits11 commented on Oct 17, 2020

    @lakshits11
    Author

    @0dinD After adding @SuppressWarnings("serial") it had gone but when I removed this and tried the other workaround, nothing happened , the warning line again came. Isn't there a way without changing the source code ?

  12. 0dinD commented on Oct 17, 2020

    @0dinD
    Contributor

    @lakshits11 Yes, you should be able to ignore the warning without adding the @SuppressWarnings annotation. This used to work by just adding the related preference to .settings/org.eclipse.jdt.core.prefs, but as we've unfortunately found out this is currently broken for the so-called "invisible projects". This feature with the invisible projects was added a while ago to reduce the amount of unnecessary files in your project directory.

    I'm sure we'll find a fix for this in a future update, but in the meantime your best option is to convert the project into an Eclipse project, by following the instructions in my previous comment. If my instructions didn't work, I just realized there could be another action you'll have to take, which is to make sure the Java Language Server is running in "standard" mode. Please try the following:

    1. Check that you have the following project structure:
    • assignmentSix - your project folder
      • .settings - a folder
        • org.eclipse.jdt.core.prefs - a file with the contents @snjeza gave you
      • .project - a file with the contents I gave you
      • .classpath - a file with the contents I gave you
      • ... - the rest of your project files
    1. Restart VS Code, and then open any Java file.

    2. Make sure that the Java Language server is running in standard mode by checking the icon in the bottom right corner. There should be a thumbs-up icon, otherwise the language server is either not started yet or running in lightweight mode. If it's running in lightweight mode, you can start standard mode by pressing the rocket ship icon. See the gif below for which icons I mean and how to activate standard mode:
      disable-warning

    3. If you want standard mode to be enabled all the time, change the VS Code setting called java.server.launchMode to "Hybrid" or "Standard".

    Let me know if this works, I've based the solution on the assumption that you've enabled lightweight mode, since it's the most obvious reason I see for why my previous instruction didn't work.

    @snjeza Shouln't we also be able to detect Eclipse preferences when running in lightweight mode? It seems like an annoyance to have to switch to standard mode just because you want to ignore a warning or something similar. Also, should we track these problems with detecting Eclipse preferences in this issue (maybe we can rename it?), or should I create a new one for that?

  13. self-assigned this
    on Oct 17, 2020
  14. lakshits11 commented on Oct 18, 2020

    @lakshits11
    Author

    @0dinD I am sorry to say but it didn't worked 😥 . I am attaching a screenshot for reference.

    Screenshot (41)

  15. 0dinD commented on Oct 18, 2020

    @0dinD
    Contributor

    @lakshits11 The screenshot tells me that the Java Language Server is now running in standard mode, so it's strange to me that the warning still shows up. However, I just came to realize I forgot one small step in my instructions when I retraced my steps using the project you attached.

    Can you try running the command Java: Clean the Java language server workspace from the command palette (press Ctrl + Shift + P to open)? You will be prompted to confirm the action, press the "Restart and delete" button.
    clean-workspace-prompt

    This command will clean up workspace settings for the Java Language Server, which seems to be necessary after converting the project into an Eclipse project, in order for the .settings/org.eclipse.jdt.core.prefs to take effect.

    After doing this, you should see the warning disappear (fingers crossed). Sorry it had to be this complicated, this is definitely a bug with invisible projects (and lightweight mode).

  16. lakshits11 commented on Oct 18, 2020

    @lakshits11
    Author

    @0dinD After I did what you told me to do , the curvy warning lines were gone, BUT ...wait wait wait, now when I run my App.java file using java test runner extension which comes in java extension pack, it was not able to recognize my MonthException and YearException java files and Build was failed in which error in the LOG file was MonthException and YearExceptioin cannot be ressolved to a type ! ALTHOUGH , the Date Exception was recognizable and it also created a DateException.class file as output ! I mean what the .... ? How funny and disgusting is it at the same time !! It is not showing any warning / curvy line now but I am pretty sure it all happened after clearing WorkSpace cache...before it, the code was running but the warning curvy lines were still there. I am attaching the screenshots for the same.

    ** 1. Here we can see that it's not showing any error/warning etc.**
    Screenshot (42)

    ** 2. But the build was failed after I run the code. **
    Screenshot (43)

    ** 3. ERROR Message in LOG file**
    Screenshot (44)

  17. snjeza commented on Oct 18, 2020

    @snjeza
    Collaborator

    @lakshits11 could you attach your current project?

  18. lakshits11 commented on Oct 19, 2020

    @lakshits11
    Author
  19. snjeza commented on Oct 19, 2020

    @snjeza
    Collaborator

    @lakshits11 I can't reproduce the issue.
    You can try to run the Java: Clean the Java language server workspace command.

  20. added this to the Mid April 2021 milestone on Apr 15, 2021
  21. lucky-sharma06 commented on Feb 11, 2026

    @lucky-sharma06

    Java Code in vs code shows way too much warnings. I mean these are really unnecessary warnings ! Even IDEs like IntelliJ don't show these unnecessary warnings. I want to disable such warnings, but not all the warnings. Is there a way to do so, or can you please do something about it ?

    Environment
    • Operating System: Windows 10 Pro
    • JDK version:
      java 14.0.2 2020-07-14
      Java(TM) SE Runtime Environment (build 14.0.2+12-46)
      Java HotSpot(TM) 64-Bit Server VM (build 14.0.2+12-46, mixed mode, sharing)
    • Visual Studio Code version: 1.50.1
    • Java extension version: 0.69.0
    Steps To Reproduce

    Download the folder below and open in vs code

    assignmentSix.zip

    Here we see that under MonthException we see a squiggle line with warning:

    a

    Warning Given: The serializable class MonthException does not declare a static final serialVersionUID field of type longJava(536871008)

    Even IDE like IntelliJ dont show these useless warnings... b

    So is there any way to disable these warnings _(NOT ALL WARNINGS)_ I mean can I only select what warnings I want to see and what I don't?

    I know this is irrelevant but Bro please can you give your theme name

  22. lucky-sharma06 commented on Feb 11, 2026

    @lucky-sharma06

    @lakshits11 bro i know this will not help you but can u please tell the theme name vscode... plzzz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions