Open renanfranca opened 8 months ago
Reproducible in Eclipse & javac
!
Eclipse
Tag.java
package org.example;
public class Tag {
public static final String STR = "test";
}
Main.java
package org.sample;
import static org.example.Tag.STR;
public class Main {
public static void main(String[] args) {
String value = STR;
System.out.println(value);
}
}
/usr/lib/jvm/java-21-openjdk/bin/javac --enable-preview --release 21 org/sample/Main.java
org/sample/Main.java:5: error: reference to STR is ambiguous
String value = STR;
^
both variable STR in StringTemplate and variable STR in Tag match
1 error
I think this comes down to how String Templates are defined in (JEP 430). It says :
STR is a public static final field that is automatically imported into every Java source file.
So STR
becomes a kind of "restricted keyword". I think it always needs to be fully qualified now.
@rgrunber javac doesn't fail without the "--enable-preview" flag. Neither does IJ IDEA. So the bug here is to expose STR when preview features are disabled. Definitely an upstream JDT issue.
String Templates are a preview feature in Java 21 though. If --enable-preview
is not included, it's reasonable to assume the STR
field doesn't get automatically injected, hence no ambiguity.
Update: Ok, after thinking a bit ( :stuck_out_tongue_winking_eye: ) I see your point. So users could use Java 21 (and eventually Java 22, it'll be preview there also) and if we disabled --enable-preview
, it would continue to work. But what happens when the feature becomes finalized (ie. Java 23?). Then we can't protect them from the name clash.
But what happens when the feature becomes finalized (ie. Java 23?). Then we can't protect them from the name clash.
Yes, but that's a Java 23 problem.
You're right. I forgot that managed projects (like Maven, Gradle) don't have preview features enabled by default. If preview features are disabled, and this is occuring then it's a bug in JDT Core.
VSCode implicitly import java.lang.StringTemplate.STR which conflict with org.yaml.snakeyaml.nodes.Tag.STR
Environment
Steps To Reproduce
Type mismatch: cannot convert from StringTemplate.Processor<String,RuntimeException> to Tag
)[Screenshot]
Current Result
I have to change the code only to run the project: FROM:
TO:
Expected Result
Is there a configuration to solve this problem without need to explicitly use Tag.STR?
Additional Informations