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 253834

Summary: Hint interaction: ConvertAnonymousToMember produces warning about public constructor
Product: java Reporter: cezariusz <cezariusz>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal    
Priority: P3    
Version: 8.1   
Hardware: PC   
OS: Windows 8 x64   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on:    
Bug Blocks: 253817    

Description cezariusz 2015-07-27 07:41:53 UTC
Link: http://services.netbeans.org/synergy/client/app/#/case/4989/suite/1691

Product Version: NetBeans IDE Dev (Build 201507240001)
Java: 1.8.0_51; Java HotSpot(TM) 64-Bit Server VM 25.51-b03
Runtime: Java(TM) SE Runtime Environment 1.8.0_51-b16
System: Windows 8 version 6.2 running on amd64; UTF-8; pl_PL (nb)

Invoke the hint "Convert Anonymous To Member" on the following code:

    private Object foo = new Object() // HINT: Convert anonymous to member
    {
    };

It will generate:

    private Object foo = new ObjectImpl();

    private static class ObjectImpl extends Object { // HINT: Convert anonymous to member

        public ObjectImpl() {
        }
    }

The ObjectImpl constructor is public, so it leads to the warning "Constructor is declared public in non-public class". I think it should be private.
Comment 1 Svata Dedic 2015-07-30 08:27:21 UTC
the public constructor in non-public class is a 'code style' hint; it's off by default and whether it is on or not depends on the coding conventions the team adheres to.

The solution would be to check whether this hint is enabled and generate modifiers automatically, but potentially there can be many such hints checking the exact coding style - so the best approach would be probably to allow the code to undergo a SERIES of automatic transformation; the user should control which transformations are enabled or not.

making enhancement, as an example of hint interaction which should be solved.