You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False warning “This method has a constructor name” for Java 25 compact source file named main.java #4424
But VS Code Java reports this diagnostic on line 1:
This method has a constructor name
code: 67108974
source: Java
Expected behavior:
No warning should be reported. void main() is valid in a Java 25 compact source file.
Actual behavior:
The Java language server appears to infer an implicit class name from main.java, then treats void main() as a method whose name matches the class name and emits the old “constructor name” warning.
This seems like a false positive specific to Java 25 compact source files, especially when the filename is main.java.
Seems like an upstream bug in eclipse.jdt.core, so I'll file it there (and leave this one open as well to track progress of the fix being integrated here)
After taking a look at the spec, I think that this behaviour from the Java compiler is okay. The compiler forms an implicit class named "main" when the class is called "main.java", and this overlaps with the main method.
I did some research and found that this issue seems to exist across all Java versions.
I understand why this warning exists. The rule in eclipse.jdt.core is probably intended to catch mistakes like this:
publicclassUser {
publicvoidUser() { // The developer probably meant to write a constructor
}
}
In this case, the method name is the same as the class name, but it has a return type, so it is not actually a constructor.
However, public static void main(String[] args) clearly cannot be a constructor, because constructors cannot have a return type and cannot be static. Despite that, it still triggers this inspection rule when the method name matches the class name.
So I think this inspection rule has a false-positive case and is not smart enough in this scenario.
I did some research and found that this issue seems to exist across all Java versions.
I understand why this warning exists. The rule in eclipse.jdt.core is probably intended to catch mistakes like this:
public class User {
public void User() { // The developer probably meant to write a constructor
}
}
In this case, the method name is the same as the class name, but it has a return type, so it is not actually a constructor.
However, public static void main(String[] args) clearly cannot be a constructor, because constructors cannot have a return type and cannot be static. Despite that, it still triggers this inspection rule when the method name matches the class name.
So I think this inspection rule has a false-positive case and is not smart enough in this scenario.
Activity
datho7561 commentedon Jun 8, 2026
Seems like an upstream bug in eclipse.jdt.core, so I'll file it there (and leave this one open as well to track progress of the fix being integrated here)
datho7561 commentedon Jun 8, 2026
After taking a look at the spec, I think that this behaviour from the Java compiler is okay. The compiler forms an implicit class named "main" when the class is called "main.java", and this overlaps with the main method.
UnderHear commentedon Jun 9, 2026
I did some research and found that this issue seems to exist across all Java versions.
I understand why this warning exists. The rule in
eclipse.jdt.coreis probably intended to catch mistakes like this:In this case, the method name is the same as the class name, but it has a return type, so it is not actually a constructor.
However,
public static void main(String[] args)clearly cannot be a constructor, because constructors cannot have a return type and cannot bestatic. Despite that, it still triggers this inspection rule when the method name matches the class name.So I think this inspection rule has a false-positive case and is not smart enough in this scenario.
UnderHear commentedon Jun 9, 2026
datho7561 commentedon Jun 10, 2026
I think it makes sense to not warn about it in this case, given the spec also states that implicit class declarations cannot have a constructor.
datho7561 commentedon Jun 23, 2026
@UnderHear try out the latest prerelease version of the extension; the fix should be released from my testing
UnderHear commentedon Jun 24, 2026
Yep, the warning is gone now. Awesome work — the console is finally at peace. 🎉
thank u for resolving my OCD