"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/java/edu/umd/cs/findbugs/detect/AppendingToAnObjectOutputStream.java" between
findbugs-3.0.0-source.zip and findbugs-3.0.1-source.zip

About: FindBugs uses static analysis to look for bugs in Java code. Source.

AppendingToAnObjectOutputStream.java  (findbugs-3.0.0-source):AppendingToAnObjectOutputStream.java  (findbugs-3.0.1-source)
skipping to change at line 22 skipping to change at line 22
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
* *
* You should have received a copy of the GNU Lesser General Public * You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
package edu.umd.cs.findbugs.detect; package edu.umd.cs.findbugs.detect;
import java.util.Collections;
import org.apache.bcel.classfile.Method; import org.apache.bcel.classfile.Method;
import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.OpcodeStack; import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.Priorities; import edu.umd.cs.findbugs.Priorities;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.bcel.OpcodeStackDetector; import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
public class AppendingToAnObjectOutputStream extends OpcodeStackDetector { public class AppendingToAnObjectOutputStream extends OpcodeStackDetector {
BugReporter bugReporter; BugReporter bugReporter;
public AppendingToAnObjectOutputStream(BugReporter bugReporter) { public AppendingToAnObjectOutputStream(BugReporter bugReporter) {
this.bugReporter = bugReporter; this.bugReporter = bugReporter;
} }
@Override
public void visitClassContext(ClassContext classContext) {
if(hasInterestingClass(classContext.getJavaClass().getConstantPool(), Co
llections.singleton("java/io/ObjectOutputStream"))) {
super.visitClassContext(classContext);
}
}
boolean sawOpenInAppendMode; boolean sawOpenInAppendMode;
@Override @Override
public void visit(Method obj) { public void visit(Method obj) {
sawOpenInAppendMode = false; sawOpenInAppendMode = false;
} }
/* /*
* (non-Javadoc) * (non-Javadoc)
* *
skipping to change at line 60 skipping to change at line 70
@Override @Override
public void sawOpcode(int seen) { public void sawOpcode(int seen) {
if (seen != INVOKESPECIAL) { if (seen != INVOKESPECIAL) {
sawOpenInAppendMode = false; sawOpenInAppendMode = false;
return; return;
} }
String calledClassName = getClassConstantOperand(); String calledClassName = getClassConstantOperand();
String calledMethodName = getNameConstantOperand(); String calledMethodName = getNameConstantOperand();
String calledMethodSig = getSigConstantOperand(); String calledMethodSig = getSigConstantOperand();
if (!sawOpenInAppendMode) { if (!sawOpenInAppendMode) {
if (calledClassName.equals("java/io/ObjectOutputStream") && calledMe if ("java/io/ObjectOutputStream".equals(calledClassName) && "<init>"
thodName.equals("<init>") .equals(calledMethodName)
&& calledMethodSig.equals("(Ljava/io/OutputStream;)V") && "(Ljava/io/OutputStream;)V".equals(calledMethodSig)
&& stack.getStackItem(0).getSpecialKind() == OpcodeStack.Ite m.FILE_OPENED_IN_APPEND_MODE) { && stack.getStackItem(0).getSpecialKind() == OpcodeStack.Ite m.FILE_OPENED_IN_APPEND_MODE) {
bugReporter.reportBug(new BugInstance(this, "IO_APPENDING_TO_OBJ ECT_OUTPUT_STREAM", Priorities.HIGH_PRIORITY) bugReporter.reportBug(new BugInstance(this, "IO_APPENDING_TO_OBJ ECT_OUTPUT_STREAM", Priorities.HIGH_PRIORITY)
.addClassAndMethod(this).addSourceLine(this)); .addClassAndMethod(this).addSourceLine(this));
} }
return; return;
} }
if (calledClassName.equals("java/io/FileOutputStream") && calledMethodNa if ("java/io/FileOutputStream".equals(calledClassName) && "<init>".equal
me.equals("<init>") s(calledMethodName)
&& (calledMethodSig.equals("(Ljava/io/File;Z)V") || calledMethod && ("(Ljava/io/File;Z)V".equals(calledMethodSig) || "(Ljava/lang
Sig.equals("(Ljava/lang/String;Z)V"))) { /String;Z)V".equals(calledMethodSig))) {
OpcodeStack.Item item = stack.getStackItem(0); OpcodeStack.Item item = stack.getStackItem(0);
Object value = item.getConstant(); Object value = item.getConstant();
sawOpenInAppendMode = value instanceof Integer && ((Integer) value). intValue() == 1; sawOpenInAppendMode = value instanceof Integer && ((Integer) value). intValue() == 1;
} else if (!sawOpenInAppendMode) { } else if (!sawOpenInAppendMode) {
return; return;
} else if (calledClassName.equals("java/io/BufferedOutputStream") && cal } else if ("java/io/BufferedOutputStream".equals(calledClassName) && "<i
ledMethodName.equals("<init>") nit>".equals(calledMethodName)
&& calledMethodSig.equals("(Ljava/io/OutputStream;)V")) { && "(Ljava/io/OutputStream;)V".equals(calledMethodSig)) {
// do nothing // do nothing
} else if (calledClassName.equals("java/io/ObjectOutputStream") && calle } else if ("java/io/ObjectOutputStream".equals(calledClassName) && "<ini
dMethodName.equals("<init>") t>".equals(calledMethodName)
&& calledMethodSig.equals("(Ljava/io/OutputStream;)V")) { && "(Ljava/io/OutputStream;)V".equals(calledMethodSig)) {
bugReporter.reportBug(new BugInstance(this, "IO_APPENDING_TO_OBJECT_ OUTPUT_STREAM", Priorities.HIGH_PRIORITY) bugReporter.reportBug(new BugInstance(this, "IO_APPENDING_TO_OBJECT_ OUTPUT_STREAM", Priorities.HIGH_PRIORITY)
.addClassAndMethod(this).addSourceLine(this)); .addClassAndMethod(this).addSourceLine(this));
sawOpenInAppendMode = false; sawOpenInAppendMode = false;
} else { } else {
sawOpenInAppendMode = false; sawOpenInAppendMode = false;
} }
} }
} }
 End of changes. 7 change blocks. 
13 lines changed or deleted 24 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS