Eclipse compiler says undefined attribute in case of array of enumeration field in annotation

I use Spring Security 3.1.0.RC3 because the method security feature with enum privileges was introduced in 3.1.

Here is my annotation:

public @interface SecuredEnum { public PrivilegeEnum[] value(); } 

And here is how I use it:

 import static somepath1.PrivilegeEnum.SOME_PRIV1; public interface MyService extends BaseService { @SecuredEnum(SOME_PRIV1) void insertOrUpdateMyObject(MyObject myObject); } 

javac correctly compiles this code every time, but the eclipse compiler (Indigo SR1) gives an error after Project -> Clean:

 The attribute value is undefined for the annotation type SecuredEnum 

and offers a quick fix:

 Create attribute 'value()' 

So here is my workaround: I apply this fix and comment out the array field in the annotation:

 public @interface SecuredEnum { // public PrivilegeEnum[] value(); public PrivilegeEnum value(); } 

After that, eclipse compiles all classes correctly (except those where @SecuredEnum accepts two or more privileges). The next step is to uncomment the old field of the array and delete the new field created by the quick fix. As a result, everything is perfectly composed. So it is very unpleasant to do it every time the project is cleaned. Another problem is that I can not reproduce this problem with the help of a sample project, so maybe there is some important information that is not in this question text. Whose mistake, and how can this be fixed?

UPDATE: neither using an explicit array in the annotation argument (that is, adding {} brackets), nor defining the argument name ('value') explicitly or using a fully qualified enumeration value instead of static import helps

+4
source share
2 answers

There may be a problem with the retention policy that you did not specify in your user annotation. Therefore, the default retention policy belongs to the class. This should be the runtime, at least what Spring's security partners use for @Secured annotation.

 @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) public @interface SecuredEnum { public PrivilegeEnum[] value(); } 
0
source

With Eclipse Juno (4.2), I just needed to change (insert empty, delete empty) and save the file with false positive in order to get rid of the "undefined" error.

I need to do this once, every time I change the compiler settings, but then it disappears until then ...

0
source

Source: https://habr.com/ru/post/1384912/


All Articles