Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341655 - [1.5][compiler] Eclipse compiler shows error on javac-valid construct: private visibility on annotation
Summary: [1.5][compiler] Eclipse compiler shows error on javac-valid construct: privat...
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.6   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-01 13:45 EDT by Zorzella Mising name CLA
Modified: 2018-12-28 02:42 EST (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zorzella Mising name CLA 2011-04-01 13:45:46 EDT
Build Identifier: 20110218-0911

javac compiles the code below, whereas Eclipse shows a "The field Foo.Bar.BAZ is not visible" error.

**************************

public class Foo {
  
	public @interface Annotation {
		String value();
	}
	
	@Annotation(Bar.BAZ)
	private static final class Some {

	}

	public static class Bar {
		private static final String BAZ = "foo";
	}
}


Reproducible: Always
Comment 1 Olivier Thomann CLA 2011-04-01 14:00:38 EDT
If Bar is defined outside of the class Foo, then javac reports the same visibility issue.
In Eclipse, if I use Bar.BAZ inside a static field of Some, then it compiles fine:
private static final class Some {
    static Object o = Bar.BAZ;
}

this looks inconsistent.

Srikanth, please let me know what you think.
Comment 2 Olivier Thomann CLA 2011-04-01 14:04:39 EDT
It compiles fine in Eclipse if the compliance is 1.6 or above.
Could you please confirm that ?
Comment 3 Zorzella Mising name CLA 2011-04-01 14:28:17 EDT
I can still see the problem with 1.6 compliance.
Comment 4 Olivier Thomann CLA 2011-04-01 14:31:31 EDT
It works in compliance 1.6 or above because the type annotation is resolved during annotation processing. If it doesn't, then the annotation processing should be disabled.
This seems to be related to the fix for bug 316456.
Srikanth, please take a look.
Comment 5 Olivier Thomann CLA 2011-04-01 15:08:59 EDT
This should fail:
@interface Annotation {
	String value();
}
class Bar {
	private static final String BAZ = "foo";
}
public class X {
	@Annotation(Bar.BAZ)
	private static final class Some {}
}

So it looks like private fields defined within the top level type can be accessed inside member types' annotations.

This should also fail:
public class X {
	@interface Annotation {
		String value();
	}
	static class Bar {
		private static final String BAZ = "foo";
	}
}
class Y extends X {
	@Annotation(Bar.BAZ)
	private static final class Some {}
}

Also annotation processing should not have any impact on this resolution.
Comment 6 Eclipse Genie CLA 2018-12-28 02:42:35 EST
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.