Bug 366184 - Warning on unused private member even when used by inner class
Summary: Warning on unused private member even when used by inner class
Status: VERIFIED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.8   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.8 M5   Edit
Assignee: Stephan Herrmann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-09 09:14 EST by Blessed Geek CLA
Modified: 2012-01-23 03:21 EST (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 Blessed Geek CLA 2011-12-09 09:14:09 EST
Build Identifier: M20110909-1335

When a private member of a class is not used, eclipse Java editor would express it by underlining those members in yellow. Even when the private members are used by an inner class.

Reproducible: Always

Steps to Reproduce:
"The value of the field not used" warning given for

PersonListPresenter.assignedPerson 
PersonListPresenter.normalPerson
PersonListPresenter.systemPerson

But, they are indeed being used by a nested non-static class.


[code]
@Presenter( view = PersonListViewImpl.class )
public class PersonListPresenter
extends LazyPresenter<PersonListView, AdminModuleEventBus>
{
  static private List<Person> systemPerson;
  static private List<Person> normalPerson;
  private List<Person> assignedPerson;

  public enum WhichList
  {
    System, Normal, Assigned;
  }

    public class PersonListCallBack
    implements MethodCallback<Person>
    {
        public PersonListCallBack(WhichList whichlist) {
      this.whichlist = whichlist;
    }

        @Override
        public void onFailure(Method method, Throwable exception) {
          String msg = exception.getMessage();
        }

    @Override
        public void onSuccess(Method method, List<Person> personList) {
      switch(this.whichlist) {
        case System:
          systemPerson = personList;
        case Normal:
          normalPerson = personList;
        case Assigned:
          PersonListPresenter.this.assignedPerson = personList;
      }
        }

    WhichList whichlist;
  }
}
[/code]
Comment 1 Stephan Herrmann CLA 2011-12-09 13:38:45 EST
(In reply to comment #0)
> Build Identifier: M20110909-1335
> 
> When a private member of a class is not used, eclipse Java editor would express
> it by underlining those members in yellow. Even when the private members are
> used by an inner class.
> 
> Reproducible: Always
> 
> Steps to Reproduce:
> "The value of the field not used" warning given for
> 
> PersonListPresenter.assignedPerson 
> PersonListPresenter.normalPerson
> PersonListPresenter.systemPerson
> 
> But, they are indeed being used by a nested non-static class.

Please re-read the warning: it doesn't say that the field is not used but
that the value stored in the field is never used.

This seems to be true for your example, thus I intend to close as invalid
unless I'm missing a relevant detail.
Comment 2 Blessed Geek CLA 2011-12-22 18:07:47 EST
Warning given: The value of the local variable sortList is not used.

But sortlist is used:
"return sortList.get(0).isAscending()"

I am interpreting that the purpose of the warning is 
"to help me determine that I can remove the field without causing errors".

But if I follow the warning, and remove the field, certainly errors would be caused.

If the purpose in life for this yellow warning is not
"to help me determine that I can remove the field without causing errors",
then the warning feature is useless to me and cannot be relied upon because it will be difficult for me to find all the unused entrails I might have left behind, during project clean-up. That is, I would not know if eclipse is calling wolf or a real wolf is present.


[code]

AsyncDataProvider<Person> dataProvider = new AsyncDataProvider<Person>()
{
  @Override
  protected void onRangeChanged(HasData<Person> display) {
    final Range range = display.getVisibleRange();
	
    // sortlist is underlined in yellow
    final ColumnSortList sortList = PersonnelTable.this.getColumnSortList();
    int start = range.getStart();
    int end = start + range.getLength();
    Collections.sort(PersonnelTable.this.PersonnelList, new Comparator<Person>() {
      @Override
      public int compare(Person o1, Person o2) {
        if (o1 == o2)
          return 0;
		  
        int diff = -1;
        if (o1 != null)
          diff = (o2 != null) ? o1.name.compareTo(o2.name) : 1;

        return sortList.get(0).isAscending() ? diff : -diff;
      }
    });
	
    List<Person> dataInRange = PersonnelTable.this.PersonnelList.subList(start, end);

    // Push the data back into the list.
    PersonnelTable.this.setRowData(start, dataInRange);
  }
};

[/code]
Comment 3 Stephan Herrmann CLA 2011-12-22 19:10:50 EST
(In reply to comment #2)
> Warning given: The value of the local variable sortList is not used.
> 
> But sortlist is used:
> "return sortList.get(0).isAscending()"

This would be a bug.
Using your example (and adding lots of stubs for required classes / methods)
I can *only* reproduce when I set the compiler compliance to 1.5.

However, in 1.5 the @Override annotation is an error (super method is
from an interface). This error causes that the compiler skips analyzing
the body of compare(..) so the use of sortList is not seen.

As a rule of thumb: while your code contains actual errors, all warnings
may be imprecise. Please fix the errors first, then the warning will go.

Unless you are seeing this in code without compile errors, this is 
working as expected, and yes: if the warning remains after errors
have been fixed, its purpose is to signal that you could safely
delete the variable (as long as you keep side effects from assignments).
Comment 4 Stephan Herrmann CLA 2012-01-02 16:27:56 EST
Two independent defects were reported (comment 0 and comment 2).
Each has been explained to work as expected (comment 1 and comment 3).

-> closing as INVALID.
Comment 5 Srikanth Sankaran CLA 2012-01-23 03:21:01 EST
Verified for 3.8 M5 using build id: I20120122-2000