| 1 19 20 package edu.umd.cs.findbugs.detect; 21 22 23 import edu.umd.cs.findbugs.*; 24 import org.apache.bcel.classfile.*; 25 26 public class EmptyZipFileEntry extends BytecodeScanningDetector implements StatelessDetector { 27 28 private BugReporter bugReporter; 29 private int sawPutEntry; 30 private String streamType; 31 32 public EmptyZipFileEntry(BugReporter bugReporter) { 33 this.bugReporter = bugReporter; 34 } 35 36 37 38 @Override  39 public void visit(JavaClass obj) { 40 } 41 42 @Override  43 public void visit(Method obj) { 44 sawPutEntry = -10000; 45 streamType = ""; 46 } 47 48 @Override  49 public void sawOpcode(int seen) { 50 if (seen == INVOKEVIRTUAL 51 && getNameConstantOperand().equals("putNextEntry")) { 52 streamType = getClassConstantOperand(); 53 if (streamType.equals("java/util/zip/ZipOutputStream") 54 || streamType.equals("java/util/jar/JarOutputStream")) 55 sawPutEntry = getPC(); 56 else 57 streamType = ""; 58 } 59 else { 60 if (getPC() - sawPutEntry <= 7 && seen == INVOKEVIRTUAL 61 && getNameConstantOperand().equals("closeEntry") 62 && getClassConstantOperand() 63 .equals(streamType) ) 64 bugReporter.reportBug(new BugInstance( 65 this, 66 streamType.equals("java/util/zip/ZipOutputStream") ? 67 "AM_CREATES_EMPTY_ZIP_FILE_ENTRY" : 68 "AM_CREATES_EMPTY_JAR_FILE_ENTRY", 69 NORMAL_PRIORITY) 70 .addClassAndMethod(this) 71 .addSourceLine(this)); 72 73 } 74 75 76 77 78 } 79 80 } 81 | Popular Tags |