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 121932 - [60cat] Surround with try-catch wraps more than it has to
Summary: [60cat] Surround with try-catch wraps more than it has to
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Editor (show other bugs)
Version: 6.x
Hardware: PC Windows XP
: P3 blocker with 1 vote (vote)
Assignee: Jan Lahoda
URL:
Keywords:
: 121963 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-11-14 19:06 UTC by mariso
Modified: 2007-12-07 16:37 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description mariso 2007-11-14 19:06:00 UTC
[ 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.
Comment 1 Vitezslav Stejskal 2007-11-15 09:58:01 UTC
Still broken in 6.0RC1.
Comment 2 Vitezslav Stejskal 2007-11-15 09:59:42 UTC
*** Issue 121963 has been marked as a duplicate of this issue. ***
Comment 3 Jan Lahoda 2007-11-29 09:41:26 UTC
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
Comment 4 _ gsporar 2007-11-29 13:34:36 UTC
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?  :-)
Comment 5 Jan Lahoda 2007-12-03 13:31:08 UTC
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.
Comment 6 _ gsporar 2007-12-03 15:16:32 UTC
> 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.