I am trying to add a detector that will detect the occurrence of System.out.println (). As explained in this post, I wrote a detector class, findbugs.xml file and messages.xml file. I created a jar that contains my detector class, findbugs.xml and messages.xml files. I added this jar to the eclipse environment (window-> preferences-> java-> findbugs-> Plugins and misc. Settings). But it shows an invalid entry.
Detector Class:
package findbugs.custom.detector; import edu.umd.cs.findbugs.BugInstance; import edu.umd.cs.findbugs.BugReporter; import edu.umd.cs.findbugs.bcel.OpcodeStackDetector; import edu.umd.cs.findbugs.classfile.ClassDescriptor; import edu.umd.cs.findbugs.classfile.FieldDescriptor; public class CallToSystemOutPrintlnDetector2 extends OpcodeStackDetector { private BugReporter bugReporter; public CallToSystemOutPrintlnDetector2(BugReporter bugReporter) { super(); this.bugReporter = bugReporter; } public void sawOpcode(int seen) { if (seen == GETSTATIC){ try { FieldDescriptor operand = getFieldDescriptorOperand(); ClassDescriptor classDescriptor = operand.getClassDescriptor(); if ("java/lang/System".equals(classDescriptor.getClassName()) && ("err".equals(operand.getName())||"out".equals(operand.getName()))) { reportBug(); } } catch (Exception e) {
Findbugs.xml file:
<FindbugsPlugin> <Detector class="findbugs.custom.detector.CallToSystemOutPrintlnDetector2" speed="fast" /> <BugPattern abbrev="SYS_OUT_P" type="CALL_TO_SYSTEM_OUT" category="CORRECTNESS" /> </FindbugsPlugin>
messages.xml file:
<MessageCollection> <Detector class="findbugs.custom.detector.CallToSystemOutPrintlnDetector2"> <Details> <![CDATA[ <p>This detector warns about SYS_OUTs used in the code. It is a fast detector.</p> ]]> </Details> </Detector> <BugPattern type="CALL_TO_SYSTEM_OUT_BUG"> <ShortDescription>sysout detector</ShortDescription> <LongDescription>Found sysout in {1}</LongDescription> <Details> <![CDATA[ <p>This is a call to System.out.println/err method. </p> which should be avoided. ]]> </Details> </BugPattern> <BugCode abbrev="SYS_OUT_P">Found sysout</BugCode> </MessageCollection>
How can i fix this?
Manoj source share