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.
[ BUILD # : 200711050000 ] [ JDK VERSION : 1.6.0_02 ] Only the statement that can throw a checked exception should be wrapped in try block. For example, in this code NetBeans would wrap the whole block into try block, if I choose "surround with try-catch" fix for parse method. request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); new SimpleDateFormat("dd_MM_yyyy").parse(request.getParameter("date")); PrintWriter out = response.getWriter(); I believe that nobody wants NetBeans to apply the fix this way. Only corresponding statement should be wrapped into try block, like this: request.setCharacterEncoding("UTF-8"); response.setCharacterEncoding("UTF-8"); try { new SimpleDateFormat("dd_MM_yyyy").parse(request.getParameter("date")); } catch (ParseException ex) { } PrintWriter out = response.getWriter(); And the second problem is generated exception handler: catch (ParseException ex) { java.util.logging.Logger.getLogger(CreateAccountServlet.class.getName( )).log(Level.SEVERE, null, ex); } It is bad code even if I use jdk14 logging. Typically logger is a class variable.
Still broken in 6.0RC1.
*** Issue 121963 has been marked as a duplicate of this issue. ***
I have added another surround with try-catch hint ("Surround Statement with try-catch") that is supposed to work in the same way as the NB5.5 Surround with try-catch. Issue #116818 should cover the logging. Checking in src/org/netbeans/modules/java/hints/errors/UncaughtException.java; /cvs/java/hints/src/org/netbeans/modules/java/hints/errors/UncaughtException.java,v <-- UncaughtException.java new revision: 1.14; previous revision: 1.13 done Checking in src/org/netbeans/modules/java/hints/errors/Bundle.properties; /cvs/java/hints/src/org/netbeans/modules/java/hints/errors/Bundle.properties,v <-- Bundle.properties new revision: 1.9; previous revision: 1.8 done RCS file: /cvs/java/hints/src/org/netbeans/modules/java/hints/errors/OrigSurroundWithTryCatchFix.java,v done Checking in src/org/netbeans/modules/java/hints/errors/OrigSurroundWithTryCatchFix.java; /cvs/java/hints/src/org/netbeans/modules/java/hints/errors/OrigSurroundWithTryCatchFix.java,v <-- OrigSurroundWithTryCatchFix.java initial revision: 1.1 done Checking in src/org/netbeans/modules/java/hints/errors/MagicSurroundWithTryCatchFix.java; /cvs/java/hints/src/org/netbeans/modules/java/hints/errors/MagicSurroundWithTryCatchFix.java,v <-- MagicSurroundWithTryCatchFix.java new revision: 1.11; previous revision: 1.10 done RCS file: /cvs/java/hints/test/unit/src/org/netbeans/modules/java/hints/errors/OrigSurroundWithTryCatchFixTest.java,v done Checking in test/unit/src/org/netbeans/modules/java/hints/errors/OrigSurroundWithTryCatchFixTest.java; /cvs/java/hints/test/unit/src/org/netbeans/modules/java/hints/errors/OrigSurroundWithTryCatchFixTest.java,v <-- OrigSurroundWithTryCatchFixTest.java initial revision: 1.1 done Checking in test/unit/src/org/netbeans/modules/java/hints/errors/MagicSurroundWithTryCatchFixTest.java; /cvs/java/hints/test/unit/src/org/netbeans/modules/java/hints/errors/MagicSurroundWithTryCatchFixTest.java,v <-- MagicSurroundWithTryCatchFixTest.java new revision: 1.4; previous revision: 1.3 done
Great news about the new hint! :-) A couple of questions.... 1. With the new hint in place, what hints will be offered when the user highlights a line of code that throws an *unchecked* exception. The reason I ask is because in 6.0, highlighting an unchecked exception and then selecting the "Surround with try-catch" hint results in just the selected line of code being wrapped by the try block. So it does the same thing as your new "Surround Statement with try-catch." I'm wondering if this means that selecting an unchecked exception means that I will now be offered two hints that do the exact same thing but just have slightly different names. 2. Any chance this new "Surround Statement with try-catch" could be made available on the beta update center for 6.0 users? :-)
1. The selection based hint is unchanged - so in some cases one might get three "Surround with" hints for a line (two error based, Surround Statement and Surround Block, and one selection based). But I would assume such cases will be quite rare. 2. From technical point of view, there is no reason why not place it on the AUC - but it will take some time (and work), so it depends on how important is it to have it on the AUC.
> it depends on how important is it to have it on the AUC. It seems really important to me, but that's just me.... What sort of data do you need in order to determine importance? IZ votes? nbusers threads? Just let me know, and I'll see what I can find.