public class EJBInstantiation extends BytecodeScanningDetector {
private static final CollectionEJB_ANNOT_NAMES = Arrays.asList(
"Stateless", "Statefull", "MessageDriven");
private BugReporter bugReporter;
public EJBInstantiation(BugReporter bugReporter) {
this.bugReporter = bugReporter;
}
@Override
public void sawOpcode(int seen) {
try {
if ((seen == INVOKESPECIAL)
&& getNameConstantOperand().equals("")
&& getSigConstantOperand().equals("()V")) {
XClass clazz = getXClassOperand();
if (clazz != null && isEJB(clazz)) {
bugReporter.reportBug(new BugInstance(this,
"EJB_INST", HIGH_PRIORITY).addClassAndMethod(
this).addSourceLine(this));
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
private boolean isEJB(XClass clazz) throws ClassNotFoundException {
boolean result = false;
Collectionannotations = clazz
.getAnnotationDescriptors();
if (annotations != null && !annotations.isEmpty()) {
for (ClassDescriptor annotation : annotations) {
if (EJB_ANNOT_NAMES.contains(annotation.getSimpleName())) {
result = true;
break;
}
}
}
return result;
}
}
Hi, my name is Paulo, I am portuguese, and I am currently working as a freelance Software Engineer in Luxembourg. This is my personal blog, where I express my views in various subjects. You can contact me using barracadopaulo@gmail.com. Welcome!
3/23/10
FindBugs- Detecting EJB instantiation
In projects using EJB3, every now and then we bump into manual instantiation of EJBs, causing unexpected results. This is the typical issue which is very easy to automatically detect. The following FindBugs detector does the job, assuming that you annotate your EJBs:
Subscribe to:
Post Comments (Atom)
Archive
-
▼
2010
(27)
-
►
January
(12)
- IPAD
- WebLogic- EJB3 uses Spring
- A Little Less Conversation
- A tricky SQL question for an interview
- Fundamental Rights of the European Union- Article ...
- Java Posse- Holiday Special 2009/2010
- EJB4- One whish to the list
- Right to the Integrity of the Person
- Charter of Fundamental Rights of the European Unio...
- EJB and Dynamic Dependency Injection
- Nativity scene with a military vehicle
- Fighting discrimination in Lux- a joke
-
►
January
(12)
0 comments:
Post a Comment