Skip to content

Commit 1b3f3f6

Browse files
author
zhourenjian
committed
Fixing bug#1690362: Invalid name of exception object inside catch block
1 parent 460b46d commit 1b3f3f6

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/net/sf/j2s/core/astvisitors/ASTKeywordVisitor.java

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,19 +1061,39 @@ public boolean visit(TryStatement node) {
10611061
buffer.append("try ");
10621062
node.getBody().accept(this);
10631063
List catchClauses = node.catchClauses();
1064-
if (catchClauses.size() > 0) {
1065-
buffer.append(" catch (e) {\r\n");
1066-
buffer.append("if (Clazz.instanceOf (e, ");
1064+
int size = catchClauses.size();
1065+
if (size > 0) {
1066+
String catchEName = "e$$";
1067+
if (size == 1) {
1068+
CatchClause element = (CatchClause) catchClauses.get(0);
1069+
SimpleName exName = element.getException().getName();
1070+
catchEName = exName.getIdentifier();
1071+
}
1072+
buffer.append(" catch (" + catchEName + ") {\r\n");
1073+
buffer.append("if (Clazz.instanceOf (" + catchEName + ", ");
10671074
for (Iterator iter = catchClauses.iterator(); iter.hasNext();) {
10681075
CatchClause element = (CatchClause) iter.next();
10691076
element.getException().getType().accept(this);
10701077
buffer.append(")) ");
1078+
SimpleName exName = element.getException().getName();
1079+
String eName = exName.getIdentifier();
1080+
boolean notEName = false;
1081+
if (!catchEName.equals(eName)) {
1082+
buffer.append("{\r\n");
1083+
buffer.append("var ");
1084+
buffer.append(eName);
1085+
buffer.append(" = " + catchEName + ";\r\n");
1086+
notEName = true;
1087+
}
10711088
element.getBody().accept(this);
1089+
if (notEName) {
1090+
buffer.append("\r\n}");
1091+
}
10721092
if (iter.hasNext()) {
1073-
buffer.append(" else if (Clazz.instanceOf (e, ");
1093+
buffer.append(" else if (Clazz.instanceOf (" + catchEName + ", ");
10741094
}
10751095
}
1076-
buffer.append(" else {\r\nthrow e;\r\n}\r\n}");
1096+
buffer.append(" else {\r\nthrow " + catchEName + ";\r\n}\r\n}");
10771097
}
10781098
Block finallys = node.getFinally();
10791099
if (finallys != null) {

0 commit comments

Comments
 (0)