Bug 343621 - Setting "Unchecked generic type operation" to Error is disabling/hiding other Warning settings
Summary: Setting "Unchecked generic type operation" to Error is disabling/hiding other...
Status: VERIFIED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.7 RC1   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-04-21 18:06 EDT by Eric Milles CLA
Modified: 2011-05-14 15:40 EDT (History)
9 users (show)

See Also:
srikanth_sankaran: review+


Attachments
First draft (9.38 KB, patch)
2011-04-28 12:20 EDT, Olivier Thomann CLA
no flags Details | Diff
Second draft (7.92 KB, patch)
2011-04-28 12:22 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (10.42 KB, patch)
2011-05-04 13:40 EDT, Olivier Thomann CLA
no flags Details | Diff
Final patch (10.26 KB, patch)
2011-05-05 10:31 EDT, Olivier Thomann CLA
no flags Details | Diff
Proposed fix + regression test (3.53 KB, patch)
2011-05-06 09:25 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Milles CLA 2011-04-21 18:06:07 EDT
I recently set the Java > Compiler > Errors/Warnings preference for "Unchecked generic type operation" from Warning to Error. Once the project was rebuilt, a number of warnings popped up related to unnecessary @SuppressWarnings annotations (as part of the "Unused '@SuppressWarnings' token" preference).

The project contains instances of unused parameters and local variables, which were suppressed.  Now, it seems JDT is not respecting the settings for "Value of local variable is not used" and "Value of parameter is not used" (and possibly others).

 Eclipse Platform               3.7.0.I20110310-1119
 Eclipse Java Development Tools 3.7.0.v20110208-0800-7z8gFb7FMTfEULpkdZIlQtX9H155
Comment 1 Olivier Thomann CLA 2011-04-21 21:25:05 EDT
Could you please provide a test case that shows the problem?
Thanks.
Comment 2 Eric Milles CLA 2011-04-22 17:15:17 EDT
I tried to boil the problem down as much as I could.  It appears to have something to do with the use of varargs and generics together.

ErrorsWarningsExample.java:

// For Project or Workspace, under Java Compiler Errors/Warnings:
// 1) Set all options to Ignore
// 2) Set "Enable '@SuppressWarnings' annotations" to checked
// 3) Set "Unused '@SuppressWarnings' token" to Warning
// 4) Set "Suppress optional errors with '@SuppressWarnings'" to checked
// 5) Set "Value of local variable is not used" to Warning
// 6) Click Apply, then click Yes to rebuild project; no warnings should be preset
// 7) Set "Unchecked generic type operation" to Error
// 8) Click Apply, then click Yes to rebuild project; two warnings should be present

// If the body of method two is commented out, the warning in method one goes away.
// There is something about using the unchecked varargs method build that causes the warnings to appear.

public class ErrorsWarningsExample
{
    public void one()
    {
        @SuppressWarnings("unused")
        Object object = new Object();
    }

    public void two()
    {
        @SuppressWarnings({ "unchecked", "unused" })
        Object object = build();
    }

    public final Object build(Class<? super Object>... objects)
    {
        return null;
    }
}
Comment 3 Olivier Thomann CLA 2011-04-28 11:58:25 EDT
This is a consequence of the fix for bug 336648. We need to "filter out" unused locals once we know that errors are left in the unit once SuppressWarnings have been applied.
Here we have an error which is removed using @SuppressWarnings, but the unused locals warnings were not reported because this is not done if the unit has errors.

Srikanth, I have a couple of ways to handle that. I need to investigate which one is the safest one in term of performance.
Comment 4 Olivier Thomann CLA 2011-04-28 12:20:54 EDT
Created attachment 194283 [details]
First draft

This first patch filters out the unused local problem if the compilation unit contains an error that is not filtered out by SuppressWarnings annotation.
This can have a potential performance impact.
Comment 5 Olivier Thomann CLA 2011-04-28 12:22:36 EDT
Created attachment 194284 [details]
Second draft

This one does all the work in the finalizeProblems() call inside the CompilationUnitDeclaration.
It can also have a performance hit.

Srikanth, let me know what you think on these two patches.
Comment 6 Srikanth Sankaran CLA 2011-05-04 05:30:23 EDT
(In reply to comment #4)
> Created attachment 194283 [details]
> First draft

CompilationResult.java:

    - Is the following code:

	if ((newProblem.getID() & IProblem.Syntax) != 0) {
		if (newProblem.isError()) {
			this.hasSyntaxError = true;
			this.numberOfErrors++;
		}
	} else if (newProblem.isError()) {
		this.numberOfErrors++;
	}

        better written as 
        
        if (newProblem.isError()) {
	    this.numberOfErrors++;
            if ((newProblem.getID() & IProblem.Syntax) != 0) {
		this.hasSyntaxError = true;
	    }
        } 

        ??

BlockScope.java:

    - computeLocalVariablePositions: comments seems to have removed from
just above the method. Is this intentional ?

    - The following loop looks suspicious to me:

loop: for (int i = 0, max = compilationResult.problemCount; i < max; i++) {
								CategorizedProblem problem = problems[i];
								if (problem.isError()) {
									CompilationUnitDeclaration compilationUnitDeclaration = this.compilationUnitScope().referenceContext;
									if (!compilationUnitDeclaration.filterOutProblem(problem)) {
										hasError = true;
									}
									break loop;
								}
							}

    Is the "break loop" in the right place ?
Comment 7 Srikanth Sankaran CLA 2011-05-04 05:59:30 EDT
(In reply to comment #5)
> Created attachment 194284 [details]
> Second draft
> 
> This one does all the work in the finalizeProblems() call inside the
> CompilationUnitDeclaration.
> It can also have a performance hit.
> 
> Srikanth, let me know what you think on these two patches.

CompilationResult.java:

    - Same comment as before. It looks like this code could be simplified
a bit,

Blockscope.java:

    - Lingering reference to bug 336648 should be deleted.

Personally I like this patch better than the previous one. Partly, but
only partly due to the fact that I didn't fully understand the previous  
patch (per earlier comments).
Comment 8 Olivier Thomann CLA 2011-05-04 12:21:15 EDT
(In reply to comment #7)
>     - Same comment as before. It looks like this code could be simplified
> a bit,
I will fix this and attach a new patch for review.
 
>     - Lingering reference to bug 336648 should be deleted.
Ok.

> Personally I like this patch better than the previous one. Partly, but
> only partly due to the fact that I didn't fully understand the previous  
> patch (per earlier comments).
I have a preference for this patch as it is more localized.
Comment 9 Olivier Thomann CLA 2011-05-04 13:40:18 EDT
Created attachment 194745 [details]
Proposed fix + regression test

Patch made from the second patch with the cleaning requested by Srikanth.
Comment 10 Olivier Thomann CLA 2011-05-04 13:50:10 EDT
Srikanth, please review.

Satyam, please run all performance tests with this patch and report back here the results.

This might be a RC1 candidate as this looks like a regression over 3.6.2.
Comment 11 Srikanth Sankaran CLA 2011-05-05 02:41:40 EDT
Patch looks good. Suggest add the old bug number (i.e bug 336648)
to the end of the line comment // we need to check if we should discard ...
in finalizeProblems() since this fix effectively replaces the earlier
fix for that bug.
Comment 12 Satyam Kandula CLA 2011-05-05 05:12:50 EDT
(In reply to comment #10)
> Satyam, please run all performance tests with this patch and report back here
> the results.
I have run the compiler performance tests on linux and I don't see any regression.
Comment 13 Olivier Thomann CLA 2011-05-05 09:46:54 EDT
(In reply to comment #11)
> Patch looks good. Suggest add the old bug number (i.e bug 336648)
> to the end of the line comment // we need to check if we should discard ...
> in finalizeProblems() since this fix effectively replaces the earlier
> fix for that bug.
Ok, thanks. I will update the patch accordingly.
Comment 14 Olivier Thomann CLA 2011-05-05 10:31:59 EDT
Created attachment 194832 [details]
Final patch

Same patch with the previous bug id added
Comment 15 Olivier Thomann CLA 2011-05-05 10:32:24 EDT
Released for 3.7RC1.
Comment 16 Markus Keller CLA 2011-05-06 08:06:43 EDT
This fix causes a few valid test failures in jdt.ui' LocalCorrectionsQuickFixTest, e.g. here:

package test1;
public class E {
    public void foo() {
        boolean res= process();
        res= (super.hashCode() == 1);
    }
    public boolean process() {
        return true;
    }
}

When I set the severity of JavaCore.COMPILER_PB_UNUSED_LOCAL to ERROR, then I don't get any problem at all any more.
Comment 17 Markus Keller CLA 2011-05-06 08:14:30 EDT
I think in general, optional errors should not hide any warnings. In contrast to mandatory errors, optional errors don't hamper the correct analysis for warnings.
Comment 18 Srikanth Sankaran CLA 2011-05-06 09:19:07 EDT
Conservatively, it would be a better idea to revert and reopen
bug 336648 - then the current bug becomes a nop. Bug 336648 can
be looked at post 3.7
Comment 19 Olivier Thomann CLA 2011-05-06 09:22:02 EDT
We only need to check if the problem we want to remove is a warning. If not, we keep it.
The patch is ready.
Comment 20 Olivier Thomann CLA 2011-05-06 09:25:15 EDT
Created attachment 194931 [details]
Proposed fix + regression test

Complement to the previous fix.
Comment 21 Andrew Niefer CLA 2011-05-06 09:59:56 EDT
I have verified that Olivier's patch in comment #20 fixes the PDE/Build test failure from N20110505-2000
Comment 22 Olivier Thomann CLA 2011-05-06 10:03:39 EDT
I also checked that this is fixing the JDT/UI failures.
Released for RC1.
Comment 23 Olivier Thomann CLA 2011-05-06 10:47:21 EDT
In fact this is still not good enough as if unused local is set to error, the error is still reported in the case of bug 336648.
So reverting this one as well.

We will need to come up with a better way to fix interaction between different errors/warnings for 3.8.

Ideally if we could detect local usage prior to code generation, this would not longer be an issue.
Comment 24 Olivier Thomann CLA 2011-05-06 11:17:46 EDT
I preserved the code to get the number of errors inside CompilationResult. I think this is worth being done as there is nothing to do to check if a compilation result has errors.
Comment 25 Srikanth Sankaran CLA 2011-05-07 07:06:36 EDT
Does this bug have to stay open ? We can add the regression
tests for the various scenarios in this bug and close it
as WORKSFORME ?
Comment 26 Olivier Thomann CLA 2011-05-08 12:32:01 EDT
Right. This could be closed as WORKSFORME.
Comment 27 Ayushman Jain CLA 2011-05-13 03:47:34 EDT
I can't seem to reproduce the original case using steps in comment 2. After step (6), I see one warning on the unused parameter for build(..) method. 
After step (8), I see that warning only and nothing in addition.

Did something change in this bug? I expected the original case to be still present.
Comment 28 Ayushman Jain CLA 2011-05-13 03:58:32 EDT
(In reply to comment #27)
> I can't seem to reproduce the original case using steps in comment 2. After
> step (6), I see one warning on the unused parameter for build(..) method. 
> After step (8), I see that warning only and nothing in addition.
> 
> Did something change in this bug? I expected the original case to be still
> present.

Sorry my mistake. Not reproducing the case 2 is what we want to do here, and so the build I20110511-0800 gives the desired behaviour.

Hence verified.
Comment 29 Stephan Herrmann CLA 2011-05-14 15:40:46 EDT
(In reply to comment #23)
> Ideally if we could detect local usage prior to code generation, this would not
> longer be an issue.

The pending patch in bug 328830 should be a good step in that direction :)