Bug 534880 - The value for annotation attribute must be a constant expression
Summary: The value for annotation attribute must be a constant expression
Status: NEW
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.7.1a   Edit
Hardware: PC Windows 7
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact: Srikanth Sankaran CLA
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-18 15:56 EDT by Samuel Martin CLA
Modified: 2023-06-05 05:26 EDT (History)
1 user (show)

See Also:


Attachments
Minimal example, whole project (4.59 KB, application/zip)
2018-05-18 15:56 EDT, Samuel Martin CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Samuel Martin CLA 2018-05-18 15:56:03 EDT
Created attachment 274106 [details]
Minimal example, whole project

I get this error when trying to compile a file with an annotation that refers to a static final field made up of the concatenation of different Strings. It is an error because I am effectively using a compile-time constant (and javac does with it), and because, well, what is puzzling is that... changing other things such as a Javadoc, the annotated method name, etc. makes the error disappear

Description	Resource	Path	Location	Type
The value for annotation attribute Key.value must be a constant expression	MyConfig.java	/example/src/main/java	line 10	Java Problem

public interface MyConfig {

	/** 
	 * @see #configPrefix()
	 * @see #assetDuration()
	 */ // Change the reference to configPrefix from this Javadoc and the error disappears. Move this javadoc to another element and the error disappears too.
	static final String PROPS_PREFIX = "myproject";
	static final String PROPS_PREFIX_PROP = PROPS_PREFIX + ".prefix";
	
	@Key(PROPS_PREFIX_PROP) // Sometimes this line yields a compiler error...
	String configPrefix();
	
	@Key(PROPS_PREFIX_PROP) // But this line works..., even if we also mention this method from the javadoc above
	String assetDuration(); // Change this method name to "myDuration" and the error disappears
	
}

@interface Key {
	   String value();
}
Comment 1 Eclipse Genie CLA 2020-08-29 16:54:42 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 2 Eclipse Genie CLA 2022-09-03 14:59:31 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.
Comment 3 Srikanth Sankaran CLA 2023-06-05 05:26:31 EDT
Unable to reproduce this on master