condy-folding bug; static field initializer is discarded

Jorn Vernee jbvernee at xs4all.nl
Fri Aug 10 18:49:23 UTC 2018


Hello,

I think I found another bug in the condy-folding branch. I noticed when 
trying to do a static get of a constant in another compilation unit that 
the value was always `null`. Here is the code:

```
import java.lang.constant.*;
import java.lang.constant.DirectMethodHandleDesc.Kind;
import static java.lang.constant.ConstantDescs.*;

public class MyConstants {

     // Not ICE from different compilation unit
     public static final DynamicConstantDesc<String> INV_myMethod
         = DynamicConstantDesc.<String>of(BSM_INVOKE).withArgs(
             MethodHandleDesc.of(
                 Kind.STATIC,
                 ClassDesc.of("MyConstants"),
                 "myMethod",
                 CR_String
             )
         );

     public static String myMethod() {
         return "Hello: ";
     }
}
```

If I then do a `System.out.println(MyConstants.INV_myMethod);` from a 
different compilation unit, the value is `null`. Looking at javap 
output, there is no <clinit> generated for the initializer. If I do that 
manually like so:

```
     public static final DynamicConstantDesc<String> INV_myMethod;

     static {
         INV_myMethod
             = DynamicConstantDesc.<String>of(BSM_INVOKE).withArgs(
                 MethodHandleDesc.of(
                     Kind.STATIC,
                     ClassDesc.of("MyConstants"),
                     "myMethod",
                     CR_String
                 )
             );
     }
```

I get a value as expected when printing:

```
DynamicConstantDesc[ConstantBootstraps::invoke(MethodHandleDesc[STATIC/MyConstants::myMethod()String])Object]
```

This looks like a bug?

Jorn


More information about the amber-dev mailing list