You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Paul King (Jira)" <ji...@apache.org> on 2021/12/09 12:07:00 UTC
[jira] [Comment Edited] (GROOVY-10407) unchecked method invocation warning in generated stubs
[ 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:06 PM:
---------------------------------------------------------------
Your example seems to compile if you place the {{Parent}} class in its own source file.
was (Author: paulk):
You can remove the extra constructor from being generated by placing the {{Parent}} class in its own source file.
> 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)