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

STC: Generic type of Set not correctly resolved when calling ConcurrentHashMap.newKeySet()

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.0.0-beta-1
    • 4.0.0-beta-2, 3.0.11
    • Static Type Checker
    • None
    • OpenJDK 8

    Description

      The following code fails to compile when STC is enabled:

      import java.util.concurrent.ConcurrentHashMap;
      
      class Test {
      
          public void test() {
              Set<Integer> integers = ConcurrentHashMap.newKeySet();
              integers.add(1);
              integers.add(2);
              printSet(integers);
          }
      
          private void printSet(Set<Integer> integers) {
              println "$integers";
          }
      }
      

      The error reported by the compiler is:

      Exception in thread "main" org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
      Script_a26d7b8defa71ea9b230673f8bc53d80.groovy: 9: [Static type checking] - Cannot call Test#printSet(java.util.Set<java.lang.Integer>) with arguments [java.util.concurrent.ConcurrentHashMap$KeySetView<java.lang.Object, java.lang.Object>]
       @ line 9, column 9.
                 printSet(integers);
                 ^
      

      This issue is new to 4.0.0-beta-1, it has not been observed before that. It looks like the variable definition is treated as if it was def integers so the generic type of the Set is not correctly resolved.

      Attachments

        Activity

          People

            emilles Eric Milles
            latanasov Lyuben Atanasov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: