This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 252560 - Suppress Warning hint doesn't work for guarded block without SuppressWarnings
Summary: Suppress Warning hint doesn't work for guarded block without SuppressWarnings
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.1
Hardware: PC Windows 7
: P4 normal (vote)
Assignee: Svata Dedic
Depends on:
Reported: 2015-05-23 19:09 UTC by cezariusz
Modified: 2015-09-30 01:20 UTC (History)
2 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Note You need to log in before you can comment on or make changes to this bug.
Description cezariusz 2015-05-23 19:09:38 UTC
Product Version: NetBeans IDE Dev (Build 201505220001)
Java: 1.8.0_45; Java HotSpot(TM) 64-Bit Server VM 25.45-b02
Runtime: Java(TM) SE Runtime Environment 1.8.0_45-b14
System: Windows 7 version 6.1 running on amd64; UTF-8; pl_PL (nb)

Suppress Warning hint doesn't work for guarded block if there is no other SuppressWarnings annotations for this block. If there is already a SuppressWarnings, the hint work adding another warning type to it. Tested with the initComponents method, and the following warnings:
* Convert2Lambda:
  - when I had @SuppressWarnings("rawtypes"), hint worked creating @SuppressWarnings({"rawtypes", "Convert2Lambda"})
  - when I had no SuppressWarnings, hint didn't work and displayed message "Cannot apply fix in a guarded block"
* Convert2Diamond: same as above
* unchecked: same as above
* rawtypes: doesn't have a hint (see bug 250590)
Comment 1 Svata Dedic 2015-09-23 14:20:58 UTC
The trouble is that the code generator attempts to insert the annotation right before the method, more specifically in between the method and its javadoc, where the annotation would be generated under normal circumstances.
Such fix is rather tough. 

Anyway, hints should be disabled on guarded code - the user cannot do anything with it anyway. Hints based on tree kinds already checked that, but hints based on patterns lacked the guard block check.

So I take the easier path :) but the API manipulation methods will be still unable to insert @annotation before method in a guarded block. Hints suppressed in jet-main#656a757b5343
Comment 2 cezariusz 2015-09-23 14:40:21 UTC
No, please, don't disable hints completely. They work at least when there is already an annotation, adding another suppress. It will be a regression.
Comment 3 Svata Dedic 2015-09-23 18:55:15 UTC
Part of hints were already disabled; the distinction between the two types is just an implementation detail of how they are triggered. So from this point of view the 8.1beta behaviour is a defect: either all hints must be enabled for guarded blocks, or none.

Since the user typically cannot intervene with computer-maintained content inside GB (be it beaninfo feature descriptor or form init), it does not make much sense to report suggestions. 

Compiler diagnostic (errors, warnings) use a different trigger mechanism and should not be affected by this change.
Comment 4 Svata Dedic 2015-09-24 09:29:21 UTC
I've checked one more possibility how to fix the @SuppressWarning addition ... Sadly there's not currently an easy way how to express to the code generator that the fold comment which is already part of the guarded section is "sticky" and annotation should be generated before it. 

Lowering the priority, leaving open - perhaps some bright idea occurs to me.
Comment 5 Quality Engineering 2015-09-30 01:20:20 UTC
Integrated into 'main-silver', will be available in build *201509300002* on (upload may still be in progress)

User: Svata Dedic <>
Log: #252560: suppress pattern-based hints in guarded blocks