Bug 265571 - Abstract method that is not directly used is flagged as unused
Summary: Abstract method that is not directly used is flagged as unused
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.5   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 3.5 M6   Edit
Assignee: Srikanth Sankaran CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-19 18:35 EST by Remy Suen CLA
Modified: 2009-03-10 10:07 EDT (History)
1 user (show)

See Also:


Attachments
Proposed patch & test (3.78 KB, patch)
2009-02-24 00:50 EST, Srikanth Sankaran CLA
kent_johnson: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Remy Suen CLA 2009-02-19 18:35:52 EST
Build id: I20090217-2200

AbstractClass's x() method is flagged as unused. Is this the expected behaviour? I guess one could argue that it is used, albeit indirectly.

-----------------

public class QuestionableUnusedMethod {

	public void v() {
		ConcreteClass tab = new ConcreteClass();
		tab.x();
	}
	
	private abstract class AbstractClass {
		
		public abstract void x();

	}

	private class ConcreteClass extends AbstractClass {
		
		public void x() {
		}
	}	
}
Comment 1 Remy Suen CLA 2009-02-19 18:42:46 EST
I'm guessing this was introduced by bug 201912...but I'm sure you all figured that out already.
Comment 2 Kent Johnson CLA 2009-02-23 14:54:05 EST
Srikanth - please take a look at this one.
Comment 3 Srikanth Sankaran CLA 2009-02-23 22:23:53 EST
(In reply to comment #2)
> Srikanth - please take a look at this one.

Will do. This case was correctly handled in the originally proposed patch,
but seems to have fallen through the cracks subsequently.



Comment 4 Srikanth Sankaran CLA 2009-02-24 00:50:52 EST
Created attachment 126517 [details]
Proposed patch & test
Comment 5 Srikanth Sankaran CLA 2009-02-24 00:54:02 EST
(In reply to comment #4)
> Created an attachment (id=126517) [details]
> Proposed patch & test

Kent, appreciate your review and help with commit, the patch has a final
line that says :

\ No newline at end of file

Is this OK ? FYI, this line was not touched by me at all.


Comment 6 Kent Johnson CLA 2009-02-24 10:47:24 EST
Do you think we should complain about the abstract method in this case ?


class QuestionableUnusedMethod {
    private abstract class AbstractClass {
            public abstract void x();
    }

    abstract class ConcreteClass extends AbstractClass {}
}


Its never a bad idea to add the testcases that are close to the original one.
Comment 7 Remy Suen CLA 2009-02-24 11:25:25 EST
(In reply to comment #6)
> Do you think we should complain about the abstract method in this case ?

Are you talking to me, Kent?

If yes, then I guess it depends if that's all that's on the classpath and no other classes in that package is calling x(). I don't know what the compiler can do so I don't know if that kind of detection is possible. :)
Comment 8 Srikanth Sankaran CLA 2009-02-25 00:58:45 EST
(In reply to comment #6)
> Do you think we should complain about the abstract method in this case ?

    No, I don't think we should complain about unused abstract methods at all, period. 

    Either the abstract class gets implemented in a concrete incarnation
in which case it is the compiler's business to ensure that all abstract
methods get implemented or if there is no concerete incarnation of it
(i.e, the class), we should warn about the whole abstract class being
unused (not the individual abstract methods). The class unused warning
for local or private classes only of course (isOrEnclosedByPrivateType()).

    If I comment out the line

    // abstract class ConcreteClass extends AbstractClass {}

we issue a warning about AbstractClass being unused locally and if I change
ConcreteClass from having default visibility to being private,

    - we DON'T complain about AbstractClass being unused locally anymore
    - we DO instead complain about ConcreteClass being unused locally.

I think this is the right behavior.

(Ignoring for the moment the fact that the package level visibility of
ConcreteClass doesn't amount to much since you cannot further subclass it
outside this source file at least as things stand now due to the requirement
for the enclosing instance) 
Comment 9 Kent Johnson CLA 2009-02-26 13:46:10 EST
Sounds good.

Fix and tests released for 3.5M6
Comment 10 Frederic Fusier CLA 2009-03-10 10:07:31 EDT
Verified for 3.5M6 using I20090310-0100.