Skip to content

Incorrect Package Warning even with correct folder structure #905

Closed

Description

Incorrect Package error
Problem:
Even when my Java package names match the folder structure, VS Code shows an “Incorrect Package” error.

For example, my structure is:

src/
└── Model/
├── Doctor.java
├── Hello1.java
└── Tester.java

Inside Tester.java:

package Model;
public class Tester {
}

But VS Code highlights the package Model; line with:
Incorrect Package (hints: 1:9-1:14)

This error goes away only after restarting VS Code, but it keeps coming back when I open or create new files.

Steps to Reproduce:

Create a folder src/Model/

Add Tester.java with package Model;

VS Code shows "Incorrect Package" error even though structure is valid.

Expected Behavior:
The Java package should be recognized correctly without requiring a VS Code restart.

Actual Behavior:
Incorrect package warning is shown until I restart VS Code.

Activity

  1. github-actions commented on Sep 17, 2025

    @github-actions

    Hi Mithun Thomas (@mithun2003), I'm an AI Support assistant here to help with your issue. While the team reviews your request, I wanted to provide some possible tips and documentation that might help you in the meantime.

    • VS Code’s Java extension (JDT LS) must know which folders are source roots. If you just open a folder containing src/Model, it treats the workspace root as the source folder and reports any package statement as mismatched. To fix:
      • Add a build descriptor (e.g. pom.xml or build.gradle) or a Eclipse .classpath file in your project root so JDT LS auto-detects src.
      • Or explicitly mark src as a source path in your settings.json:
        "java.project.sourcePaths": [
          "src"
        ]
    • After changing your project layout or settings, reload the Java language server instead of fully restarting VS Code:
      • Run Java: Clean the Java language server workspace from the Command Palette, then reopen the project.
    • Ensure you open the folder that contains src, not src itself, as your workspace root.

    Duplicate of:

    Other references with low confidence

    The team will respond to your issue shortly. I hope these suggestions are helpful in the meantime. If this comment helped you, please give it a 👍. If the suggestion was not helpful or incorrect, please give it a 👎. Your feedback helps us improve!

  2. mithun2003 commented on Sep 17, 2025

    @mithun2003
    Author

    Thanks for the quick reply. I’ve already tried the suggested steps:

    My settings.json already contains:

    "java.project.sourcePaths": ["src"],
    "java.project.outputPath": "bin",
    

    I am opening the project root (the folder containing src/, not src directly).

    I also tried Java: Clean the Java language server workspace from the command palette, but the problem still persists.

    The issue remains:

    When I create or open a file inside src/Model/, VS Code shows Incorrect Package under package Model;.

    The error disappears only after restarting VS Code, which suggests it’s not picking up source paths properly until restart.

    So this doesn’t seem to be just a configuration issue, but possibly a bug in the Java Language Server’s handling of new files/folders without restart.

  3. DonPalwo commented on May 27, 2026

    @DonPalwo

    The error disappears only after restarting VS Code, which suggests it’s not picking up source paths properly until restart.

    Did not work for me. Almost spend the half day on it .... moving to Netbeans

  4. chagong commented on Jun 10, 2026

    @chagong
    Contributor

    Mithun Thomas (@mithun2003) can you share the extension versions of your"Extension Pack for Java" and "Language Support for Java by Red hat"?

    DonPalwo, do you see the exact the same error? Would you like to share your extension versions?

  5. github-actions commented on Jul 11, 2026

    @github-actions

    This issue has been closed automatically because it needs more information and has not had recent activity. Please reach out if you have or find the answers we need so that we can investigate further.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions