| Summary: | eclipse IDE shows compilation error while javac compiles | ||
|---|---|---|---|
| Product: | [Eclipse Project] JDT | Reporter: | boris chlopkov <boris.chlopkov> |
| Component: | Core | Assignee: | JDT-Core-Inbox <jdt-core-inbox> |
| Status: | CLOSED WONTFIX | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | jarthana, stephan.herrmann |
| Version: | 4.7 | ||
| Target Milestone: | --- | ||
| Hardware: | PC | ||
| OS: | Windows 7 | ||
| Whiteboard: | stalebug | ||
Self-contained example:
//---
@interface Foobar {
int foobar();
}
public class Foo {
final int foobarValue = 2+2;
@Foobar(foobar = foobarValue)
class Bar{
@Foobar(foobar = foobarValue)
void foobarChildMethod() {}
}
}
//---
Error:
----------
1. ERROR in /tmp/Foo.java (at line 8)
@Foobar(foobar = foobarValue)
^^^^^^^^^^^
Cannot make a static reference to the non-static field foobarValue
----------
This is long standing behaviour of ecj.
Where in JLS is defined whether an annotation value is in an instance scope or a static scope?
From gut feeling I'd say, that meta data (compile time values) cannot reference instance variables; class files cannot reference runtime values (which instance fields inevitably are).
At first glance this looks to me like a bug in javac. Any evidence to the contrary? Is there an explicit case about static instance fields whose value is a compile time constant?
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. As such, we're closing this bug. If you have further information on the current state of the bug, please add it and reopen this bug. 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. |
using java 1.8, this valid code below doesn't compile in eclipse IDE: public class Foo { final int foobarValue = 2+2; @Foobar(foobar = foobarValue) class Bar{ @Foobar(foobar = foobarValue) void foobarChildMethod() {} } }