Joseph Price created GROOVY-10407:
-------------------------------------
Summary: unchecked method invocation warning in generated stubs
Key: GROOVY-10407
URL: https://issues.apache.org/jira/browse/GROOVY-10407
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 3.0.9
Reporter: Joseph Price
When calling a groovy class from java that takes a Map in the constructor, the
generated stubs have what looks to be a second constructor that takes a null
for the parameter, that casted to a raw Map. Since this happens in generated
code not under my control, this prevents enabling -Werror across the project.
Providing type arguments for the map or leaving the cast off would fix the
warning, but I also wonder if suppressing the constructor is possible.
Below are the commands I ran, along with the contents of the java and groovy
files:
{code:java}
groovyc -j -FWerror -FXlint:unchecked Test.java Base.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Compile error during compilation with javac.
/var/folders/mm/8s324dkd6sb1ktx0g48pbvhc0000gq/T/groovy-generated--java-source3303303787390544788/Base.java:13:
warning: [unchecked] unchecked method invocation: constructor <init> in class
Parent is applied to given types
super ((java.util.Map)null);
^
required: Map<String,String>
found: Map
/var/folders/mm/8s324dkd6sb1ktx0g48pbvhc0000gq/T/groovy-generated--java-source3303303787390544788/Base.java:13:
warning: [unchecked] unchecked conversion
super ((java.util.Map)null);
^
required: Map<String,String>
found: Map
error: warnings found and -Werror specified
1 error
2 warnings
{code}
{code:java}
cat -p Base.groovy
class Parent {
Parent(Map<String, String> map) {
}
}
class Base extends Parent {
Base(Map<String, String> map) {
super(map);
}
}
cat -p Test.java
import java.util.Map;
class Test {
Base b = new Base(Map.of());
} {code}
--
This message was sent by Atlassian Jira
(v8.20.1#820001)