Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 382743 - [quick fix] Eclipse suggests a variable's visibility should be changed to "protected" but that variable is already protected
Summary: [quick fix] Eclipse suggests a variable's visibility should be changed to "pr...
Status: CLOSED DUPLICATE of bug 65876
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.8   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-06-15 10:18 EDT by Will Harwood CLA
Modified: 2012-06-18 21:41 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Will Harwood CLA 2012-06-15 10:18:09 EDT
Build Identifier: Version: Helios Service Release 2 Build id: 20110218-0911

Given these two classes:


package p;
public class A {
       protected int x;
}

package q;
public class B extends A {
       public void bla(A a) {
	      System.out.println(a.x); //(1)
       }
}

(1) is correctly identified as being in error (as we aren't in the same package as A, we can't access its protected variable "x". Note that since we haven't cast to B, it's irrelevant that B extends A, only the same-package rule is used.)

However, as a fix eclipse suggests changing the visibility of x to protected, but it is already protected. 

If the "extends A" is removed from the definition of B, the eclipse-suggested fix is, Change x to be public. Which should be the suggested fix here too. 



Reproducible: Always

Steps to Reproduce:
Reproduced using these two packages/classes:


package p;
public class A {
       protected int x;
}

package q;
public class B extends A {
       public void bla(A a) {
	      System.out.println(a.x); 
       }
}
Comment 1 Ayushman Jain CLA 2012-06-15 10:36:17 EDT
Moving to JDT/UI.

See also bug 341209
Comment 2 Deepak Azad CLA 2012-06-18 21:41:09 EDT

*** This bug has been marked as a duplicate of bug 65876 ***