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 182060

Summary: "Surround Statement with try-catch" should pick available logger
Product: java Reporter: err <err>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: NEW ---    
Severity: normal CC: cezariusz, jpokorsky, wadechandler
Priority: P2    
Version: 6.x   
Hardware: PC   
OS: Windows XP   
Issue Type: ENHANCEMENT Exception Reporter:
Bug Depends on: 252708    
Bug Blocks:    

Description err 2010-03-15 16:15:47 UTC
This hint produces something like

    Logger.getLogger(SwingTextView.class.getName()).
            log(Level.SEVERE, null, ex);

But in the SwingTextView class there is

    static final Logger LOG = Logger.getLogger(SwingTextView.class.getName());

(the "final" is there because of a recent hint ;-) )

Shouldn't the try-catch hint produce

    LOG.log(Level.SEVERE, null, ex);

Alternatively, or perhaps in addition, there could be a hint, something like,
"use existing Logger" which would convert the try-catch output.
Comment 1 Jan Lahoda 2010-05-18 13:03:43 UTC
I will see what can be done.
Comment 2 areeda 2010-06-12 21:48:04 UTC
If I may add a request.  When it is necessary to create/get the default logger I'd rather see this.getClass().getName() used instead of MyClass.class.getName().

I find I sometimes copy/paste then edit.  Since the results are equivalent but class independent, I think it'll be a wee bit better.
Comment 3 err 2010-06-12 23:30:28 UTC
Sadly "this.getClass().getName()" can only be used in instance context, and not in static context.
Comment 4 eclesia 2010-06-13 09:11:07 UTC
Most of the time we already have a defined logger in the class, usualy it can be found in :
- a static field named LOGGER 
- by a method .getLogger()
So if the automatic try{} catch could check if those exist that would be great.
Comment 5 _ wadechandler 2011-12-22 13:49:18 UTC
I just noticed this as well, and was going to add a bug and saw it was already here :-). Adding myself to the cc.
Comment 6 Svata Dedic 2013-09-04 14:58:56 UTC
Actually an enhancement; the generated code is valid, although not optimal.
Comment 7 cezariusz 2015-05-31 09:44:53 UTC
*** Bug 208460 has been marked as a duplicate of this bug. ***
Comment 8 cezariusz 2015-05-31 09:47:03 UTC
(In reply to eclesia from comment #4)
> usualy it can be found in :

It could be defined as an option. See bug 252708.