Bug 190970 - [javadoc] "field never read locally" analysis should not consider javadoc
Summary: [javadoc] "field never read locally" analysis should not consider javadoc
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 normal with 1 vote (vote)
Target Milestone: 3.4 M3   Edit
Assignee: Eric Jodet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-06-05 03:51 EDT by Genady Beryozkin CLA
Modified: 2007-10-29 07:58 EDT (History)
6 users (show)

See Also:


Attachments
[file]: proposed fix with 2 test cases (5.12 KB, patch)
2007-06-06 13:06 EDT, Eric Jodet CLA
no flags Details | Diff
[file]: better patch (5.23 KB, patch)
2007-06-07 00:40 EDT, Eric Jodet CLA
no flags Details | Diff
[file]: patch with new Javadoc comment (5.32 KB, patch)
2007-06-07 02:29 EDT, Eric Jodet CLA
no flags Details | Diff
[patch] improved version (5.31 KB, patch)
2007-08-28 06:42 EDT, Eric Jodet CLA
no flags Details | Diff
as per Philippe suggestion in comment #13 - all jdt.core tests OK (11.63 KB, patch)
2007-08-29 07:59 EDT, Eric Jodet CLA
no flags Details | Diff
patch + test case (34.16 KB, patch)
2007-09-03 02:40 EDT, Eric Jodet CLA
no flags Details | Diff
[proposed patch + test case] on top v815 - all jdt.core tests OK (6.03 KB, patch)
2007-10-01 09:23 EDT, Eric Jodet CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Genady Beryozkin CLA 2007-06-05 03:51:09 EDT
Build ID: 3.3RC2

Currently having a javadoc referencing a private field causes the "never read locally" warning to disappear.

The analysis should only consider "real" read access.
Comment 1 Eric Jodet CLA 2007-06-06 04:16:05 EDT
(In reply to comment #0)
Did not manage to reproduce the behavior you described.
Though having Javadoc comments referencing an unused private field,
the "never read locally" warning is still present.
May you please provide us with some sample code that reproduces described behavior?
Thanks.
Comment 2 Genady Beryozkin CLA 2007-06-06 04:33:24 EDT
Clean install of 3.3RC3:


public class Class1 {

	private int unused;
	
	/**
	 * Same value as {@link #unused}
	 */
	private int unused2;
}

The field "unused" is not marked as "never read locally".
Comment 3 Philipe Mulet CLA 2007-06-06 06:44:40 EDT
This is an interesting discussion. Same applies to private/local methods (or should).

When a user cares about javadoc consistency (which is the case here), is it ok to let him discard the field, and thus get a problem in his javadoc ?

Comment 4 Eric Jodet CLA 2007-06-06 06:50:09 EDT
(In reply to comment #2)
the position of the Javadoc comment impacts the behavior:
- if the Javadoc is placed before the declaration, then the warning is raised
- if the Javadoc is placed after (which is the case here), then no warning anymore
(reproduced using a 3.2.2)
Comment 5 Philipe Mulet CLA 2007-06-06 09:39:40 EDT
Hmm... then indeed this motivates ignoring javadoc then.
Comment 6 Philipe Mulet CLA 2007-06-06 09:40:11 EDT
Eric - pls investigate a fix.
Comment 7 Eric Jodet CLA 2007-06-06 13:06:20 EDT
Created attachment 70372 [details]
[file]: proposed fix with 2 test cases

Added 2 corresponding test cases org.eclipse.jdt.internal.compiler.ast#test445 and test446.
All jdt.core tests completed.
Comment 8 Eric Jodet CLA 2007-06-07 00:40:26 EDT
Created attachment 70450 [details]
[file]: better patch
Comment 9 Frederic Fusier CLA 2007-06-07 01:49:20 EDT
OK for me.

However, I have two cosmetic remarks:
1) I would have kept a method name with deprecated as the goal of this method is to verify whether the field use is deprecated or not: isFieldDeprecated, fieldUseDeprecated or isFieldUseDeprecate...
2) IMO, method javadoc comment could be clearer:
/**
 * Same implementation than {@link ASTNode#isFieldUseDeprecated(...)} without 
 * touching the {@link ExtraCompilerModifiers#AccLocallyUsed} to keep private 
 * fields unused when they are only referenced in javadoc comments.
 *
 * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=190970"
 */
Comment 10 Eric Jodet CLA 2007-06-07 02:21:23 EDT
(In reply to comment #9)
Thanks for the review.
1 - I've integrated your Javadoc comment proposal
2 - Regarding the method name, I selected this one as, as I understand it, it's more than checking whether the field is deprecated or not (we also check access restriction).
Comment 11 Eric Jodet CLA 2007-06-07 02:29:14 EDT
Created attachment 70465 [details]
[file]: patch with new Javadoc comment
Comment 12 Eric Jodet CLA 2007-08-28 06:42:03 EDT
Created attachment 77111 [details]
[patch] improved version
Comment 13 Philipe Mulet CLA 2007-08-29 06:26:16 EDT
I'd rather avoid having overriding method duplicate so much from the super method. Pls rather introduce a boolean param to original method to condition the usageCheck.
Comment 14 Eric Jodet CLA 2007-08-29 07:59:45 EDT
Created attachment 77238 [details]
as per Philippe suggestion in comment #13 - all jdt.core tests OK
Comment 15 Jerome Lanneluc CLA 2007-08-29 11:58:50 EDT
Since this is not a regression comparing to 3.2 (the same problem existed in 3.2), we will target 3.4.
Comment 16 Eric Jodet CLA 2007-08-31 04:47:24 EDT
(In reply to comment #14)
Please review last proposed patch
Comment 17 Frederic Fusier CLA 2007-08-31 07:10:38 EDT
(In reply to comment #16)
> (In reply to comment #14)
> Please review last proposed patch
> 
KO for me as same issue exist for method references in javadoc and is not fixed by the patch:

public class TestMethods {

        private void unused1() {}

        /**
         * Same value as {@link #unused1()}
         */
        private void unused2() {}
}
Comment 18 Eric Jodet CLA 2007-08-31 07:23:42 EDT
(In reply to comment #17)
correct: Philippe's comment #3 was not taken into account.
Comment 19 Philipe Mulet CLA 2007-08-31 07:54:17 EDT
I also suspect private/local types to also reveal the same issue.
Comment 20 Eric Jodet CLA 2007-09-03 02:40:33 EDT
Created attachment 77558 [details]
patch + test case

covers unused fields, methods and types
Comment 21 Jerome Lanneluc CLA 2007-09-04 11:40:15 EDT
(In reply to comment #20)
The patch looks good to me. So +1 for this patch.

Comment 22 Frederic Fusier CLA 2007-09-28 09:50:54 EDT
(In reply to comment #20)
> Created an attachment (id=77558) [details]
> patch + test case
> 
> covers unused fields, methods and types
> 
The patch is not good as the added tests pass without the fix applied on org.eclipse.jdt.core project: so, -1 for me
Comment 23 Eric Jodet CLA 2007-10-01 09:23:43 EDT
Created attachment 79473 [details]
[proposed patch + test case] on top v815 - all jdt.core tests OK

as per Frederic buddy check:
- corrected test cases
- alternative patch that uses ASTNode.InsideJavadoc to determine whether
Comment 24 Eric Jodet CLA 2007-10-01 09:24:35 EDT
(In reply to comment #23)
... whether a field, method or type is used or not.
Comment 25 Jerome Lanneluc CLA 2007-10-03 10:36:54 EDT
(In reply to comment #23)
Indeed, much simpler. +1

Comment 26 Eric Jodet CLA 2007-10-04 09:08:03 EDT
Released for 3.4M3 in HEAD stream
Comment 27 David Audel CLA 2007-10-29 07:58:28 EDT
Verified for 3.4M3 using I20071029-0010 build.