-
Bug
-
Resolution: Unresolved
-
P4
-
17, 21, 22
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Java version: 21.0.1
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
A DESCRIPTION OF THE PROBLEM :
I get the errors (see log at "Actual Result") from javac for code using generics in an obviously valid way and had to add casts to raw type as a workaround.
Please note that the Eclipse Compiler perfectly compiles my code.
You can find my code here:
https://github.com/m-m-m/property/blob/1a9b411eb0294187504090a87e17184816757a77/core/src/main/java/io/github/mmm/property/factory/PropertyFactoryManager.java#L88
As you can see the method has this generic declaration:
<V, P extends ReadableProperty<V>>
The called method getRequiredFactory has this generic declaration:
<V, P extends ReadableProperty<V>>
IMHO it should therefore be quite obvious that the method call should work without the cast to "Class" without the generic.
In this place we have the same pattern with even just a single method parameter:
https://github.com/m-m-m/property/blob/1a9b411eb0294187504090a87e17184816757a77/core/src/main/java/io/github/mmm/property/factory/PropertyFactoryManager.java#L159C17-L159C42
I work on Java 17 in this project but just tested with the latest 21 version to confirm the bug is not already fixed.
IMHO there is no version of javac that can compile this code. However, Eclipse Compiler works fine.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
https://github.com/m-m-m/property/actions/runs/6751066732/job/18354544566
https://github.com/m-m-m/property/commit/a8a75e9e1543859683f22c0328fac2a9f6eb1c8e
https://github.com/m-m-m/property/actions/runs/6751081583
https://github.com/m-m-m/property/actions
You can also clone the repository https://github.com/m-m-m/property.git and build yourself but the project consists of many modules so the setup may take some time. IMHO the description and the source should easily convince there is a bug and with it you should easily be able to isolate the bug pattern with minimum code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
javac should compile my code
ACTUAL -
[ERROR] D:\projects\mmm\workspaces\main\property\core\src\main\java\io\github\mmm\property\factory\PropertyFactoryManager.java:[87,48] error: incompatible types: inference variable P#1 has incompatible bounds
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>,String,PropertyMetadata<V#2>)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>,String,PropertyMetadata<V#2>)
[ERROR] D:\projects\mmm\workspaces\main\property\core\src\main\java\io\github\mmm\property\factory\PropertyFactoryManager.java:[116,48] error: incompatible types: inference variable P#1 has incompatible bounds
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,PropertyTypeInfo<V#2>,String,PropertyMetadata<V#2>)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,PropertyTypeInfo<V#2>,String,PropertyMetadata<V#2>)
[ERROR] D:\projects\mmm\workspaces\main\property\core\src\main\java\io\github\mmm\property\factory\PropertyFactoryManager.java:[156,41] error: incompatible types: inference variable P#1 has incompatible bounds
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getFactoryForPropertyType(Class<P#1>)
V#1 extends Object declared in method <V#1,P#1>getFactoryForPropertyType(Class<P#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>getFactory(Class<P#2>,Class<V#2>)
V#2 extends Object declared in method <V#2,P#2>getFactory(Class<P#2>,Class<V#2>)
---------- BEGIN SOURCE ----------
https://github.com/m-m-m/property/blob/a8a75e9e1543859683f22c0328fac2a9f6eb1c8e/core/src/main/java/io/github/mmm/property/factory/PropertyFactoryManager.java#L88
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add casts to remove generic type information losing type-safeness
FREQUENCY : always
Java version: 21.0.1
Default locale: en_US, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
A DESCRIPTION OF THE PROBLEM :
I get the errors (see log at "Actual Result") from javac for code using generics in an obviously valid way and had to add casts to raw type as a workaround.
Please note that the Eclipse Compiler perfectly compiles my code.
You can find my code here:
https://github.com/m-m-m/property/blob/1a9b411eb0294187504090a87e17184816757a77/core/src/main/java/io/github/mmm/property/factory/PropertyFactoryManager.java#L88
As you can see the method has this generic declaration:
<V, P extends ReadableProperty<V>>
The called method getRequiredFactory has this generic declaration:
<V, P extends ReadableProperty<V>>
IMHO it should therefore be quite obvious that the method call should work without the cast to "Class" without the generic.
In this place we have the same pattern with even just a single method parameter:
https://github.com/m-m-m/property/blob/1a9b411eb0294187504090a87e17184816757a77/core/src/main/java/io/github/mmm/property/factory/PropertyFactoryManager.java#L159C17-L159C42
I work on Java 17 in this project but just tested with the latest 21 version to confirm the bug is not already fixed.
IMHO there is no version of javac that can compile this code. However, Eclipse Compiler works fine.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
https://github.com/m-m-m/property/actions/runs/6751066732/job/18354544566
https://github.com/m-m-m/property/commit/a8a75e9e1543859683f22c0328fac2a9f6eb1c8e
https://github.com/m-m-m/property/actions/runs/6751081583
https://github.com/m-m-m/property/actions
You can also clone the repository https://github.com/m-m-m/property.git and build yourself but the project consists of many modules so the setup may take some time. IMHO the description and the source should easily convince there is a bug and with it you should easily be able to isolate the bug pattern with minimum code.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
javac should compile my code
ACTUAL -
[ERROR] D:\projects\mmm\workspaces\main\property\core\src\main\java\io\github\mmm\property\factory\PropertyFactoryManager.java:[87,48] error: incompatible types: inference variable P#1 has incompatible bounds
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>,String,PropertyMetadata<V#2>)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,Class<V#2>,String,PropertyMetadata<V#2>)
[ERROR] D:\projects\mmm\workspaces\main\property\core\src\main\java\io\github\mmm\property\factory\PropertyFactoryManager.java:[116,48] error: incompatible types: inference variable P#1 has incompatible bounds
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
V#1 extends Object declared in method <V#1,P#1>getRequiredFactory(Class<P#1>,Class<V#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>create(Class<P#2>,PropertyTypeInfo<V#2>,String,PropertyMetadata<V#2>)
V#2 extends Object declared in method <V#2,P#2>create(Class<P#2>,PropertyTypeInfo<V#2>,String,PropertyMetadata<V#2>)
[ERROR] D:\projects\mmm\workspaces\main\property\core\src\main\java\io\github\mmm\property\factory\PropertyFactoryManager.java:[156,41] error: incompatible types: inference variable P#1 has incompatible bounds
equality constraints: P#2
upper bounds: WritableProperty<V#1>,ReadableProperty<V#1>
where P#1,V#1,P#2,V#2 are type-variables:
P#1 extends ReadableProperty<V#1> declared in method <V#1,P#1>getFactoryForPropertyType(Class<P#1>)
V#1 extends Object declared in method <V#1,P#1>getFactoryForPropertyType(Class<P#1>)
P#2 extends ReadableProperty<V#2> declared in method <V#2,P#2>getFactory(Class<P#2>,Class<V#2>)
V#2 extends Object declared in method <V#2,P#2>getFactory(Class<P#2>,Class<V#2>)
---------- BEGIN SOURCE ----------
https://github.com/m-m-m/property/blob/a8a75e9e1543859683f22c0328fac2a9f6eb1c8e/core/src/main/java/io/github/mmm/property/factory/PropertyFactoryManager.java#L88
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Add casts to remove generic type information losing type-safeness
FREQUENCY : always