Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Package name not recognized when opening standalone java files #1764

Closed
fbricon opened this issue May 7, 2021 · 3 comments · Fixed by #1767
Closed

Package name not recognized when opening standalone java files #1764

fbricon opened this issue May 7, 2021 · 3 comments · Fixed by #1767
Assignees
Labels
Milestone

Comments

@fbricon
Copy link
Contributor

fbricon commented May 7, 2021

If you open a folder containing src/mypackage/Foo.java, with

package mypackage;

public class Foo {}

You end up with The declared package "mypackage" does not match the expected package ""

See attached project

Screenshot 2021-05-07 at 15 35 01

@fbricon fbricon added the bug label May 7, 2021
@rgrunber
Copy link
Contributor

rgrunber commented May 7, 2021

For a source file placed under mypackge.yourpackage correctly, the classpath entry for the sources is incorrectly defined as _/src/mypackage/yourpackage (as opposed to just _/src). After a restart, it seems to get it right, and I'm also seeing the behaviour where a second restart seems to eliminate the source entry entirely.

InvisibleProjectImporter is probably a good starting point.

@snjeza
Copy link
Contributor

snjeza commented May 7, 2021

The issue has been introduced by #1658
A workaround is to add

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

to .vscode/settings.json

@snjeza snjeza self-assigned this May 7, 2021
@rgrunber
Copy link
Contributor

It probably makes sense to add "src" to that list, if it's empty to avoid regressions with clients who don't set this property.

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