Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10407

unchecked method invocation warning in generated stubs

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 3.0.9
    • 3.0.10, 4.0.0-rc-2, 2.5.21
    • Compiler
    • None

    Description

       

      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:

      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                                                                      

       

      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());
      } 

       

       

       

      Attachments

        Activity

          People

            emilles Eric Milles
            joseph.price Joseph Price
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: