JDK-8317966 : Raw type not supported for a template processor in a template expression
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 22
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • Submitted: 2023-10-11
  • Updated: 2023-11-06
  • Resolved: 2023-11-06
Related Reports
Duplicate :  
Duplicate :  
Description
String Templates Preview Feature:

According to the spec:

The type, TP, of the TemplateProcessor expression must be a subtype of StringTemplate.Processor, or a compile-time error occurs. If TP is a subtype of StringTemplate.Processor<Result,Exc>, where Result and Exc are the type arguments of the parameterized type, then the type of the template expression is Result. If TP is a subtype of the raw type StringTemplate.Processor, then the type of the template expression is Object.

But this behaviour for raw types is not preserved by the compiler. For example, the following incorrectly results in a compile-time error. 

class TemplateTest {
    public static void main(String[] args) {
        StringTemplate.Processor s = STR;
        String name = "J_Laskey";
        var x = s."Hello \{name}";
    }
}

$ ./build/macosx-x86_64-server-release/images/jdk/bin/javac --enable-preview --source 22 TemplateTest.java
TemplateTest.java:18: error: processor type cannot be a raw type: Processor
       var x = s."Hello \{name}";
               ^
Note: TemplateTest.java uses preview features of Java SE 22.
Note: Recompile with -Xlint:preview for details.
1 error


Comments
Changes included in JEP 463
06-11-2023