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

Method closure somehow doesn't match argument

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Critical
    • Resolution: Fixed
    • 4.0.8
    • 3.0.16, 4.0.10
    • Compiler
    • None

    Description

      I do not understand at all how this is happening, but when I pass class literals to a method closure whose parameter is a Class, I'm getting MissingMethodException. This seems to have something to do with ASTTs, because it only happens when TupleConstructor is involved. In my business code, TupleConstructor on a top-level containing class triggers the error on a static nested class; I have a repro, but I'm only able to make it trigger on the specific class involved.

      In any case, in my business code I'm using @CompileStatic, but that doesn't seem to be protecting me against runtime dynamic dispatch.

      @Grab(group='software.amazon.awssdk', module='dynamodb-enhanced', version='2.19.25')
      import software.amazon.awssdk.enhanced.dynamodb.mapper.annotations.*
      import software.amazon.awssdk.enhanced.dynamodb.TableSchema
      import java.util.function.Function
      import groovy.transform.*
      
      @DynamoDbBean @TupleConstructor(defaults=false)
      class TopLevel {
          String id
      
          @DynamoDbPartitionKey
          String getId() { id }
      
          @DynamoDbBean
          @ToString
          static class Nested {
              String id
      
              @DynamoDbPartitionKey
              String getId() { id }
          }
      }
      
      // https://javadoc.io/static/software.amazon.awssdk/dynamodb-enhanced/2.19.25/software/amazon/awssdk/enhanced/dynamodb/TableSchema.html#fromClass-java.lang.Class-
      Function<Class<?>, TableSchema<?>> func = TableSchema.&fromClass
      func.apply(TopLevel) // XXX
      func.apply(TopLevel.Nested)
      
      Condition failed with Exception:
      
      func.apply(TopLevel)
      |    |     |
      |    |     class com.example.TopLevel
      |    groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.runtime.MethodClosure.fromClass() is applicable for argument types: (Class) values: [class com.example.TopLevel]
      |    Possible solutions: getClass(), metaClass(groovy.lang.Closure)
      |    	at com.example.BugRepl.top-level(BugRepl.groovy:19)
      org.codehaus.groovy.runtime.MethodClosure@6a472566
      

      I'm tagging this as critical because it's a "can't-possibly-happen" bug (at least in static mode) that has apparently been latent in an internal library for months and is still present as of 4.0.8.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              chrylis Christopher Smith
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: