3

I am trying to annotate the JRE method <T> T[] toArray(T[] a) from java.util.Set using Eclipse's external null annotations. The expected effect should be equivalent to this:

 public interface Set<E> extends Collection<E> {
     ...
     <T> T @NonNull[] toArray(T @NonNull[] a);
     ...
 }

When using Eclipse's Annotate command I can annotate the return type of the method properly (after I selected the T[] and position the cursor before the [). However trying to do the same with the parameter fails. Pressing Cmd-1 simply beeps, as does selecting "Annotate" when calling the command from the context menu.

I finally ended up editing the corresponding Set.eea file manually to defined the required annotation, taking care of the proper eea file layout. I.e. I changed the annotatedSignature in:

class java/util/Set
toArray
 <T:Ljava/lang/Object;>([TT;)[TT;
 <T:Ljava/lang/Object;>([TT;)[1TT;

to

 <T:Ljava/lang/Object;>([1TT;)[1TT;

This works fine and the annotation is correctly processed by the compiler.

As I can annotate the return type but not a parameter type I am wondering what I am doing wrong. Or is this a limitation of the current Eclipse version?

I am using Eclipse Mars Release (4.5.0, Build id: 20150621-1200) and jdk1.8.0_60.

Nathan
  • 8,093
  • 8
  • 50
  • 76
Udo Borkowski
  • 311
  • 1
  • 9
  • Somewhat offtopic: Is there a pre-compiled collection of these external annotations? Or are you maintaining your own collection? – HRJ Sep 22 '15 at 07:46
  • 2
    @HRJ I am maintaining my own collection of external annotation files. However I am planning to make them "open source" and publish them soon (via GitHub). I will leave a note here when this is done. – Udo Borkowski Sep 22 '15 at 08:44

1 Answers1

2

This is a bug indeed, I just filed https://bugs.eclipse.org/477461 to track this.

This was bug 464081 which got fixed for 4.6 M1 (i.e., is available in current builds towards Eclipse Neon) and is currently proposed for 4.5.2 (Mars.2)

Stephan Herrmann
  • 7,963
  • 2
  • 27
  • 38