[
https://issues.apache.org/jira/browse/GROOVY-10407?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17456355#comment-17456355
]
Paul King edited comment on GROOVY-10407 at 12/9/21, 12:22 PM:
---------------------------------------------------------------
A workaround in your example is to place the {{Parent}} class in its own source
file and compile in the fashion you describe. No warning is given.
Looking at the generated stubs in each case doesn't show any difference and if
you happen to also mention {{Parent.groovy}} on your {{groovyc}} command, the
error returns. I'll have to check but I think type erasure for the {{Parent}}
class is coming into play.
was (Author: paulk):
Your example seems to compile if you place the {{Parent}} class in its own
source file.
But looking at the generated stub in each case doesn't show any difference that
would explain the difference in behavior.
> 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
> Priority: Minor
>
>
> 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)