Re: [type-annos-observers] some errors in the specification (january 30 version)

Remi Forax forax at univ-mlv.fr
Sun Mar 3 06:47:02 PST 2013


Wild guesses !

Resource Variable:
try(@Interned AutoClosable a=null) {
}

Constructor invocation argument:
class A {
  <T> A() {}
}
...
A a = new <@Interned Integer> A();

All other constructions are 1.8 specific.

Cheers,
Rémi

Sent from my Phone

----- Reply message -----
From: "Eric Bruneton" <ebruneton at free.fr>
To: <type-annotations-spec-comments at openjdk.java.net>
Cc: "FORAX" <remi.forax at univ-mlv.fr>
Subject: [type-annos-observers] some errors in the specification (january 30 version)
Date: Sun, Mar 3, 2013 10:35


03/03/2013 00:07, Werner Dietl wrote:
> I've now changed throws and extends to shorts, as in the discussion in
> the message above.
> I've pushed this fix:
>
> http://hg.openjdk.java.net/type-annotations/type-annotations/langtools/rev/15010e417af5
>
> Note how the ClassReader and other parts already used u2s and only the
> writer was inconsistent.

Thanks for the fix. Actually my email was wrong, I wanted to say "catch 
clauses" instead of "throws clauses". They are also using u1 in the RI 
and u2 in the specification. I hadn't noticed that throws and extends 
clauses were wrong too!

I tried to fix that myself in com.sun.tools.classfile.ClassWriter 
(ClassReader is also wrong), following your patch, but it took me some 
time to realize that in fact this code is not used when compiling 
classes. Instead, it is com.sun.tools.javac.jvm.ClassWriter (where 
extends and throws clause are correctly implemented, which is why I 
didn't notice the error in the other ClassWriter class).

With the fix in the jvm.ClassWriter class, I can correctly read a class 
produced by javac with ASM, regenerate it via a null ASM transform, read 
it again with ASM and obtain the same output. I checked almost all kind 
of type annotations, except
- RESOURCE_VARIABLE
- CONSTRUCTOR_REFERENCE_RECEIVER
- METHOD_REFERENCE_RECEIVER
- CONSTRUCTOR_INVOCATION_TYPE_ARGUMENT
- CONSTRUCTOR_REFERENCE_TYPE_ARGUMENT
- METHOD_REFERENCE_TYPE_ARGUMENT
I don't know if can generate them with langtools, if it's based on 1.7. 
I'm currently using the following test program:

import java.util.*;

public class InterningExample<@Interned T extends ArrayList<@Interned 
?>> extends @Interned ArrayList implements @Interned Cloneable {

   @Interned String s;

   public void example(@Interned String @Interned [] @Interned [] f) {
     @Interned String foo = "foo";
     @Interned String bar = "bar";
     if (foo instanceof @Interned String) return;
     if (foo == (@Interned String) bar)
       System.out.println("foo == bar");
   }

   public @Interned int m(@Interned InterningExample<T> this, @Interned 
T e) {
     return 0;
   }

   public void n() throws @Interned Exception {
     InterningExample.<@Interned T>mm(0);
     new @Interned ArrayList<@Interned T>();
   }

   public static <@Interned T extends ArrayList<@Interned ?>> T mm(int t) {
     try {
       return null;
     } catch (@Interned Exception e) {
     }
     return null;
   }
}

with

import java.lang.annotation.*;
@Documented
@Inherited
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE_USE, ElementType.TYPE_PARAMETER})
public @interface Interned {}

Eric


More information about the type-annotations-spec-comments mailing list