Thread: [Fb-contrib-commit] SF.net SVN: fb-contrib: [636] trunk/fb-contrib/src/com/mebigfatguy/ fbcontrib/
Brought to you by:
dbrosius
From: <dbr...@us...> - 2006-09-07 22:25:00
|
Revision: 636 http://svn.sourceforge.net/fb-contrib/?rev=636&view=rev Author: dbrosius Date: 2006-09-07 15:24:54 -0700 (Thu, 07 Sep 2006) Log Message: ----------- reduce false positives in LEST by, not looking at finally blocks, and tossing previous catch blocks when pc = handlerpc. This removes some reports due to nested exceptions in catch blocks, but better than too liberal. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-09-04 21:36:43 UTC (rev 635) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-09-07 22:24:54 UTC (rev 636) @@ -163,14 +163,19 @@ int pc = getPC(); for (CodeException ex : exceptions) { if (pc == ex.getEndPC()) { - if ((seen >= IRETURN) && (seen <= RETURN)) - addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); - else if ((seen == GOTO) || (seen == GOTO_W)) - addCatchBlock(ex.getHandlerPC(), this.getBranchTarget()); - else - addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); + if (ex.getCatchType() != 0) + { + if ((seen >= IRETURN) && (seen <= RETURN)) + addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); + else if ((seen == GOTO) || (seen == GOTO_W)) + addCatchBlock(ex.getHandlerPC(), this.getBranchTarget()); + else + addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); + } return; - } + } else if (pc == ex.getHandlerPC()) { + removePreviousHandlers(pc); + } } Iterator<CatchInfo> it = catchInfos.iterator(); @@ -178,21 +183,8 @@ try { CatchInfo catchInfo = it.next(); if (pc == catchInfo.getStart()) { - if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { - int reg = RegisterUtils.getAStoreReg(this, seen); - catchInfo.setReg(reg); - exReg.put(Integer14.valueOf(reg), Boolean.TRUE); - LocalVariableTable lvt = getMethod().getLocalVariableTable(); - if (lvt != null) { - LocalVariable lv = lvt.getLocalVariable(reg, pc+2); - if (lv != null) { - int finish = lv.getStartPC() + lv.getLength(); - if (finish < catchInfo.getFinish()) - catchInfo.setFinish(finish); - } - } - break; - } + updateExceptionRegister(catchInfo, seen, pc); + break; } else if (pc > catchInfo.getFinish()) { it.remove(); break; @@ -265,6 +257,34 @@ } } + private void removePreviousHandlers(int pc) + { + //This unnecessarily squashes some nested catch blocks, but better than false positives + Iterator<CatchInfo> it = catchInfos.iterator(); + while (it.hasNext()) { + CatchInfo ci = it.next(); + if (ci.getStart() < pc) + it.remove(); + } + } + + private void updateExceptionRegister(CatchInfo ci, int seen, int pc) { + if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { + int reg = RegisterUtils.getAStoreReg(this, seen); + ci.setReg(reg); + exReg.put(Integer14.valueOf(reg), Boolean.TRUE); + LocalVariableTable lvt = getMethod().getLocalVariableTable(); + if (lvt != null) { + LocalVariable lv = lvt.getLocalVariable(reg, pc+2); + if (lv != null) { + int finish = lv.getStartPC() + lv.getLength(); + if (finish < ci.getFinish()) + ci.setFinish(finish); + } + } + } + } + private void addCatchBlock(int start, int finish) { CatchInfo ci = new CatchInfo(start, finish); catchInfos.add(ci); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-09-08 23:18:49
|
Revision: 637 http://svn.sourceforge.net/fb-contrib/?rev=637&view=rev Author: dbrosius Date: 2006-09-08 16:18:40 -0700 (Fri, 08 Sep 2006) Log Message: ----------- if a localvariable table exists, and exception variable cannot be found in the table, then the catch block is empty, so ignore. Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-09-07 22:24:54 UTC (rev 636) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-09-08 23:18:40 UTC (rev 637) @@ -183,7 +183,8 @@ try { CatchInfo catchInfo = it.next(); if (pc == catchInfo.getStart()) { - updateExceptionRegister(catchInfo, seen, pc); + if (!updateExceptionRegister(catchInfo, seen, pc)) + it.remove(); break; } else if (pc > catchInfo.getFinish()) { it.remove(); @@ -268,7 +269,18 @@ } } - private void updateExceptionRegister(CatchInfo ci, int seen, int pc) { + /** + * looks to update the catchinfo block with the register used for the + * exception variable. If their is a local variable table, but the local + * variable can't be found return false, signifying an empty catch block. + * + * @param ci the catchinfo record for the catch starting at this pc + * @param seen the opcode of the currently visited instruction + * @param pc the current pc + * + * @return whether the catch block is empty + */ + private boolean updateExceptionRegister(CatchInfo ci, int seen, int pc) { if ((seen == ASTORE) || ((seen >= ASTORE_0) && (seen <= ASTORE_3))) { int reg = RegisterUtils.getAStoreReg(this, seen); ci.setReg(reg); @@ -281,10 +293,20 @@ if (finish < ci.getFinish()) ci.setFinish(finish); } + else + return false; } } + return true; } + /** + * add a catch block info record for the catch block that is guessed to be + * in the range of start to finish + * + * @param start the handler pc + * @param finish the guessed end of the catch block + */ private void addCatchBlock(int start, int finish) { CatchInfo ci = new CatchInfo(start, finish); catchInfos.add(ci); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-09-16 04:38:54
|
Revision: 652 http://svn.sourceforge.net/fb-contrib/?rev=652&view=rev Author: dbrosius Date: 2006-09-15 21:38:48 -0700 (Fri, 15 Sep 2006) Log Message: ----------- remove some false positives Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-09-16 03:39:53 UTC (rev 651) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-09-16 04:38:48 UTC (rev 652) @@ -172,7 +172,6 @@ else addCatchBlock(ex.getHandlerPC(), Integer.MAX_VALUE); } - return; } else if (pc == ex.getHandlerPC()) { removePreviousHandlers(pc); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-10 23:37:09
|
Revision: 668 http://svn.sourceforge.net/fb-contrib/?rev=668&view=rev Author: dbrosius Date: 2006-10-10 16:37:05 -0700 (Tue, 10 Oct 2006) Log Message: ----------- don't report LEST if the exception that is thrown was compiled with a jdk less than version 1.4 Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-10 06:01:42 UTC (rev 667) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-10 23:37:05 UTC (rev 668) @@ -84,8 +84,7 @@ @Override public void visitClassContext(ClassContext classContext) { try { - int majorVersion = classContext.getJavaClass().getMajor(); - if ((throwableClass != null) && (majorVersion >= Constants.MAJOR_1_4)) { + if ((throwableClass != null) && (!isPre14Class(classContext.getJavaClass()))) { stack = new OpcodeStack(); catchInfos = new HashSet<CatchInfo>(); exReg = new HashMap<Integer, Boolean>(); @@ -217,10 +216,13 @@ OpcodeStack.Item itm = stack.getStackItem(0); if ((itm.getRegisterNumber() != catchInfo.getRegister()) && (itm.getUserValue() == null)) { - bugReporter.reportBug(new BugInstance(this, "LEST_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY) - .addClass(this) - .addMethod(this) - .addSourceLine(this)); + if (!isPre14Class(itm.getJavaClass())) + { + bugReporter.reportBug(new BugInstance(this, "LEST_LOST_EXCEPTION_STACK_TRACE", NORMAL_PRIORITY) + .addClass(this) + .addMethod(this) + .addSourceLine(this)); + } it.remove(); break; } @@ -257,6 +259,16 @@ } } + /** returns whether the class in question was compiled with a jdk less than 1.4 + * + * @param exClass the class to check + * @return whether the class is compiled with a jdk less than 1.4 + */ + private boolean isPre14Class(JavaClass cls) + { + return cls.getMajor() < Constants.MAJOR_1_4; + } + private void removePreviousHandlers(int pc) { //This unnecessarily squashes some nested catch blocks, but better than false positives This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2006-10-11 00:04:08
|
Revision: 669 http://svn.sourceforge.net/fb-contrib/?rev=669&view=rev Author: dbrosius Date: 2006-10-10 17:04:00 -0700 (Tue, 10 Oct 2006) Log Message: ----------- the handler pc can equal the end pc Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-10 23:37:05 UTC (rev 668) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2006-10-11 00:04:00 UTC (rev 669) @@ -142,7 +142,7 @@ public CodeException[] collectExceptions(CodeException[] exceptions) { List<CodeException> filteredEx = new ArrayList<CodeException>(); for (CodeException ce : exceptions) { - if ((ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() < ce.getHandlerPC())) { + if ((ce.getStartPC() < ce.getEndPC()) && (ce.getEndPC() <= ce.getHandlerPC())) { filteredEx.add(ce); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <dbr...@us...> - 2007-02-07 22:48:06
|
Revision: 844 http://svn.sourceforge.net/fb-contrib/?rev=844&view=rev Author: dbrosius Date: 2007-02-07 14:46:16 -0800 (Wed, 07 Feb 2007) Log Message: ----------- if throwing InvocationTargetException.getTargetException don't report as LEST Modified Paths: -------------- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java =================================================================== --- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2007-02-07 04:52:12 UTC (rev 843) +++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/LostExceptionStackTrace.java 2007-02-07 22:46:16 UTC (rev 844) @@ -199,18 +199,22 @@ break; } } - } else if ((seen == INVOKEVIRTUAL) && "initCause".equals(getNameConstantOperand())) { - String className = getClassConstantOperand(); - JavaClass exClass = Repository.lookupClass(className); - if (exClass.instanceOf(throwableClass)) { - if (stack.getStackDepth() > 1) { - OpcodeStack.Item itm = stack.getStackItem(1); - int reg = itm.getRegisterNumber(); - if (reg >= 0) - exReg.put(Integer14.valueOf(reg), Boolean.TRUE); - markAsValid = true; // Fixes javac generated code - } - } + } else if (seen == INVOKEVIRTUAL) { + if ("initCause".equals(getNameConstantOperand())) { + String className = getClassConstantOperand(); + JavaClass exClass = Repository.lookupClass(className); + if (exClass.instanceOf(throwableClass)) { + if (stack.getStackDepth() > 1) { + OpcodeStack.Item itm = stack.getStackItem(1); + int reg = itm.getRegisterNumber(); + if (reg >= 0) + exReg.put(Integer14.valueOf(reg), Boolean.TRUE); + markAsValid = true; // Fixes javac generated code + } + } + } else if ("getTargetException".equals(getNameConstantOperand()) && "java/lang/reflect/InvocationTargetException".equals(getClassConstantOperand())) { + markAsValid = true; + } } else if (seen == ATHROW) { if (stack.getStackDepth() > 0) { OpcodeStack.Item itm = stack.getStackItem(0); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |