[ 
https://issues.apache.org/jira/browse/GROOVY-9853?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17540440#comment-17540440
 ] 

Eric Milles edited comment on GROOVY-9853 at 5/21/22 3:09 PM:
--------------------------------------------------------------

Isolated a bit further:
{code:groovy}
@groovy.transform.CompileStatic
def test() {
  java.util.function.Function<CharSequence> f = CharSequence::length
  f.applyAsInt("")
}
print test()
{code}

Java equivalent that runs successfully:
{code:java}
public class Groovy9853 {
  public static void main(String[] args) throws Exception {
    java.util.function.ToIntFunction<CharSequence> f = CharSequence::length;
    System.err.println(f.applyAsInt(""));
  }
}
{code}

{code}
// Compiled from Temporary.java (version 1.8 : 52.0, super bit)
public class Temporary {
  
  // Method descriptor #6 ()V
  // Stack: 1, Locals: 1
  public Temporary();
    0  aload_0 [this]
    1  invokespecial java.lang.Object() [8]
    4  return
      Line numbers:
        [pc: 0, line: 3]
      Local variable table:
        [pc: 0, pc: 5] local: this index: 0 type: Temporary
  
  // Method descriptor #15 ([Ljava/lang/String;)V
  // Stack: 3, Locals: 2
  public static void main(java.lang.String[] args) throws java.lang.Exception;
     0  invokedynamic 0 applyAsInt() : java.util.function.ToIntFunction [19]
     5  astore_1 [f]
     6  getstatic java.lang.System.err : java.io.PrintStream [23]
     9  aload_1 [f]
    10  ldc <String ""> [29]
    12  invokeinterface 
java.util.function.ToIntFunction.applyAsInt(java.lang.Object) : int [31] 
[nargs: 2]
    17  invokevirtual java.io.PrintStream.println(int) : void [36]
    20  return
      Line numbers:
        [pc: 0, line: 5]
        [pc: 6, line: 6]
        [pc: 20, line: 25]
      Local variable table:
        [pc: 0, pc: 21] local: args index: 0 type: java.lang.String[]
        [pc: 6, pc: 21] local: f index: 1 type: java.util.function.ToIntFunction
      Local variable type table:
        [pc: 6, pc: 21] local: f index: 1 type: 
java.util.function.ToIntFunction<java.lang.CharSequence>
      Method Parameters:
        args

  Inner classes:
    [inner class info: #70 java/lang/invoke/MethodHandles$Lookup, outer class 
info: #72 java/lang/invoke/MethodHandles
     inner name: #74 Lookup, accessflags: 25 public static final]
Bootstrap methods:
  0 : # 58 invokestatic 
java/lang/invoke/LambdaMetafactory.metafactory:(Ljava/lang/invoke/MethodHandles$Lookup;Ljava/lang/String;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodType;Ljava/lang/invoke/MethodHandle;Ljava/lang/invoke/MethodType;)Ljava/lang/invoke/CallSite;
        Method arguments:
                #59 (Ljava/lang/Object;)I
                #66 null
                #68 (Ljava/lang/CharSequence;)I
}
{code}


was (Author: emilles):
Isolated a bit further:
{code:groovy}
@groovy.transform.CompileStatic
def test() {
  java.util.function.Function<CharSequence> f = CharSequence::length
  f.applyAsInt("")
}
print test()
{code}

Java equivalent that runs successfully:
{code:java}
public class Groovy9853 {
  public static void main(String[] args) throws Exception {
    java.util.function.ToIntFunction<CharSequence> f = CharSequence::length;
    System.err.println(f.applyAsInt(""));
  }
}
{code}

> ClassFormatError using method reference on interface target
> -----------------------------------------------------------
>
>                 Key: GROOVY-9853
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9853
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 3.0.7, 4.0.2
>            Reporter: Christopher Smith
>            Priority: Major
>
> After upgrading to 3.0.7, using {{interfaceField::method}} is resulting in 
> bytecode output containing an InterfaceMethodref that looks as expected. When 
> running it in the Eclipse JUnit runner, however (which I think is 
> unimportant), I'm getting a loading error from the JVM:
> {code}
> Caused by: java.lang.ClassFormatError: Invalid constant pool index 130 in 
> class file com/example/sendgrid/SendgridMailSender (not a method)
> {code}
> where the offending constant is
> {code}
>   #130 = InterfaceMethodref #126.#129     // 
> com/sendgrid/SendGridAPI.api:(Lcom/sendgrid/Request;)Lcom/sendgrid/Response;
> {code}
> from the 4.6.8 SendGrid SDK.
> Compiling with 3.0.6 seems to work. Replacing {{::}} with {{.&}} seems to 
> work.
> The JVM is 11.0.9-hs-adpt.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to