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

No report for two Classes in the same package with same name #1111

Open
liangjiancang opened this issue Oct 21, 2019 · 2 comments
Open

No report for two Classes in the same package with same name #1111

liangjiancang opened this issue Oct 21, 2019 · 2 comments

Comments

@liangjiancang
Copy link

Just as the title says, eclipse will report it.

Environment
  • Operating System: Windows 10
  • JDK version: 1.8.0_161
  • Visual Studio Code version: 1.39.2
  • Java extension version: 0.51.0
Steps To Reproduce
// src/test/C1.java
package test;
public class C1 {}
class Same {}
// src/test/C2.java
package test;
public class C2 {}
class Same {}
Current Result

No problem dectected.
Fail to build.

@liangjiancang liangjiancang changed the title Not report that two Classes in the same package with same name No report for two Classes in the same package with same name Oct 23, 2019
@rgrunber
Copy link
Member

rgrunber commented Jan 18, 2024

$ javac *.java
C2.java:4: error: duplicate class: org.example.Same
class Same {
^
1 error

Eclipse reports The type Same is already defined via ECJ. Not sure why it isn't working in vscode-java.

Update: vscode-java reports it as well but there's still a bug.

C1.java

package org.example;
public class C1 {}

class Same {
}

C2.java

package org.example;
public class C2 {}

class Same {
}

Open up C1.java first, and the language server will begin to load.

I see :

[Trace - 23:21:11] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///tmp/foo/org/example/C2.java",
    "diagnostics": [
        {
            "range": {
                "start": {
                    "line": 3,
                    "character": 6
                },
                "end": {
                    "line": 3,
                    "character": 10
                }
            },
            "severity": 1,
            "code": "0",
            "source": "Java",
            "message": "The type Same is already defined"
        }
    ]
}

Now open up C1.java

[Trace - 23:23:11] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///tmp/foo/org/example/C2.java",
    "diagnostics": []
}

The message disappears.

Looking at https://github.com/eclipse-jdt/eclipse.jdt.core/blob/35bf3605e3a1fba5c0864479d04fef13452f9046/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CompilationUnitScope.java#L170-L177 it almost seems like didOpen might be losing information about the other parsed files.

@rgrunber rgrunber added the bug label Jan 18, 2024
@rgrunber
Copy link
Member

If one uses Java: Force Java Compilation from the command palette, the error returns. This is starting to look like a case where didOpen on a single file masks some errors that a full compilation would reveal.

It seems like a diagnostic that requires a full build is placed on a single file, so the way to persist it is probably to set the URI for the diagnostic as that of the project.

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

No branches or pull requests

3 participants