Community
Participate
Working Groups
The following invalid annotation is accepted as legitimate: public @interface MyAnnotation { enum MyEnum { VAL_1, VAL_2 } public MyEnum theValue() default null; //<-- this should not be allowed } To compound the problem, if you call MethodBinding.getDefaultValue() on that method, you get an IllegalStateException. java.lang.IllegalStateException: java.lang.Object@b3a420 at org.eclipse.jdt.core.dom.ResolvedMemberValuePair.buildDOMValue(ResolvedMemberValuePair.java:91) at org.eclipse.jdt.core.dom.MethodBinding.getDefaultValue(MethodBinding.java:451)
The null case is not checked in the enum case.
Created attachment 37042 [details] Proposed fix
Created attachment 37043 [details] Corresponding regression test
Fix looks good
Fixed and released in HEAD. Regression test in org.eclipse.jdt.core.tests.compiler.regression.AnnotationTest.test196
After this fix, will a call to getDefaultValue() on a method with an invalid null default still throw a IllegalStateException?
Yes, since null should not happen.
I could not get the IllegalStateException with or without the fix on a 3.2 build. null is returned instead.
We are still seeing the exception. I should have made this clear: I cut off the stack trace so it is: java.lang.IllegalStateException: java.lang.Object@b3a420 at org.eclipse.jdt.core.dom.ResolvedMemberValuePair.buildDOMValue(ResolvedMemberValuePair.java:91) at org.eclipse.jdt.core.dom.MethodBinding.getDefaultValue(MethodBinding.java:451) at ... where "..." is external (non-JDT) code calling in. I think any time code calls getDefaultValue() on an invalid null default value. This is a problem, because even though the code is not valid, it can still show up in source. Are you seeing something different?
What version are you using? I don't have the class org.eclipse.jdt.core.dom.ResolvedMemberValuePair anymore. It is now called org.eclipse.jdt.core.dom.MemberValuePairBinding.
Verified for 3.2 M6 using build I20060329-0010.
Dan was using the APT branch of jdt.core (3.1.2). Looking at the latest in HEAD, the same problem still exists: an IllegalStateException could be thrown if the user's source code is invalid. I'll attach a proposed fix for the IllegalStateException: return null instead.
Created attachment 37224 [details] Fix for IllegalStateException
Fixed and released in HEAD.
Verified. There is nothing more to verify that what was done before.