use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class JAXRSIssues method visitMethod.
@Override
public void visitMethod(Method obj) {
if (obj.isSynthetic()) {
return;
}
String path = null;
boolean isJAXRS = false;
boolean hasGet = false;
boolean hasConsumes = false;
for (AnnotationEntry entry : obj.getAnnotationEntries()) {
String annotationType = entry.getAnnotationType();
switch(annotationType) {
case "Ljavax/ws/rs/GET;":
hasGet = true;
isJAXRS = true;
break;
case "Ljavax/ws/rs/Consumes;":
hasConsumes = true;
break;
case "Ljavax/ws/rs/Path;":
path = getDefaultAnnotationValue(entry);
break;
default:
// it is fine that GET is not captured here
if (METHOD_ANNOTATIONS.contains(annotationType)) {
isJAXRS = true;
}
break;
}
if (hasGet && hasConsumes) {
bugReporter.reportBug(new BugInstance(this, BugType.JXI_GET_ENDPOINT_CONSUMES_CONTENT.name(), NORMAL_PRIORITY).addClass(this).addMethod(this));
break;
}
}
if (isJAXRS) {
processJAXRSMethod(obj, pathOnClass + path, hasConsumes || hasClassConsumes);
}
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class JPAIssues method catalogFieldOrMethod.
/**
* parses a field or method for spring-tx or jpa annotations
*
* @param fm
* the currently parsed field or method
*/
private void catalogFieldOrMethod(FieldOrMethod fm) {
for (AnnotationEntry entry : fm.getAnnotationEntries()) {
String type = entry.getAnnotationType();
switch(type) {
case "Lorg/springframework/transaction/annotation/Transactional;":
if (fm instanceof Method) {
boolean isWrite = true;
for (ElementValuePair pair : entry.getElementValuePairs()) {
if ("readOnly".equals(pair.getNameString())) {
isWrite = "false".equals(pair.getValue().stringifyValue());
break;
}
}
transactionalMethods.put(new FQMethod(cls.getClassName(), fm.getName(), fm.getSignature()), isWrite ? TransactionalType.WRITE : TransactionalType.READ);
}
break;
case "Ljavax/persistence/Id;":
hasId = true;
break;
case "Ljavax/persistence/GeneratedValue;":
hasGeneratedValue = true;
break;
case "Ljavax/persistence/OneToMany;":
for (ElementValuePair pair : entry.getElementValuePairs()) {
if ("fetch".equals(pair.getNameString()) && "EAGER".equals(pair.getValue().stringifyValue())) {
hasEagerOneToMany = true;
break;
}
}
break;
case "Lorg/hibernate/annotations/Fetch;":
case "Lorg/eclipse/persistence/annotations/JoinFetch;":
case "Lorg/eclipse/persistence/annotations/BatchFetch;":
hasFetch = true;
break;
default:
break;
}
}
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class JPAIssues method getAnnotatedRollbackExceptions.
/**
* parses an spring-tx @Transactional annotations for rollbackFor/noRollbackfor attributes of a @Transactional annotation.
*
* @param method
* the currently parsed method
*
* @return the exception classes declared in the @Transactional annotation
*
* @throws ClassNotFoundException
* if exception classes are not found
*/
private Set<JavaClass> getAnnotatedRollbackExceptions(Method method) throws ClassNotFoundException {
for (AnnotationEntry annotation : method.getAnnotationEntries()) {
if ("Lorg/springframework/transaction/annotation/Transactional;".equals(annotation.getAnnotationType())) {
if (annotation.getNumElementValuePairs() == 0) {
return Collections.<JavaClass>emptySet();
}
Set<JavaClass> rollbackExceptions = new HashSet<>();
for (ElementValuePair pair : annotation.getElementValuePairs()) {
if ("rollbackFor".equals(pair.getNameString()) || "noRollbackFor".equals(pair.getNameString())) {
String exNames = pair.getValue().stringifyValue();
Matcher m = annotationClassPattern.matcher(exNames);
while (m.find()) {
String exName = m.group(1);
JavaClass exCls = Repository.lookupClass(SignatureUtils.trimSignature(exName));
if (!exCls.instanceOf(runtimeExceptionClass)) {
rollbackExceptions.add(exCls);
}
}
}
}
return rollbackExceptions;
}
}
return Collections.<JavaClass>emptySet();
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class OverlyConcreteParameter method visitMethod.
/**
* implements the visitor to look to see if this method is constrained by a superclass or interface.
*
* @param obj
* the currently parsed method
*/
@Override
public void visitMethod(Method obj) {
methodSignatureIsConstrained = false;
String methodName = obj.getName();
if (!Values.CONSTRUCTOR.equals(methodName) && !Values.STATIC_INITIALIZER.equals(methodName)) {
String methodSig = obj.getSignature();
methodSignatureIsConstrained = methodIsSpecial(methodName, methodSig) || methodHasSyntheticTwin(methodName, methodSig);
if (!methodSignatureIsConstrained) {
for (AnnotationEntry entry : obj.getAnnotationEntries()) {
if (CONVERSION_ANNOTATIONS.contains(entry.getAnnotationType())) {
methodSignatureIsConstrained = true;
break;
}
}
}
if (!methodSignatureIsConstrained) {
String parms = methodSig.split("\\(|\\)")[1];
if (parms.indexOf(Values.SIG_QUALIFIED_CLASS_SUFFIX_CHAR) >= 0) {
outer: for (JavaClass constrainCls : constrainingClasses) {
Method[] methods = constrainCls.getMethods();
for (Method m : methods) {
if (methodName.equals(m.getName()) && methodSig.equals(m.getSignature())) {
methodSignatureIsConstrained = true;
break outer;
}
}
}
}
}
}
}
use of org.apache.bcel.classfile.AnnotationEntry in project fb-contrib by mebigfatguy.
the class WiringIssues method visitClassContext.
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "SF_SWITCH_NO_DEFAULT", justification = "Only a few cases need special handling")
@Override
public void visitClassContext(ClassContext classContext) {
try {
JavaClass cls = classContext.getJavaClass();
Field[] fields = cls.getFields();
if (fields.length > 0) {
Map<WiringType, FieldAnnotation> wiredFields = new HashMap<>();
boolean loadedParents = false;
for (Field field : fields) {
boolean hasAutowired = false;
String qualifier = "";
for (AnnotationEntry entry : field.getAnnotationEntries()) {
switch(entry.getAnnotationType()) {
case SPRING_AUTOWIRED:
if (!loadedParents) {
loadParentAutowireds(cls.getSuperClass(), wiredFields);
loadedParents = true;
}
hasAutowired = true;
break;
case SPRING_QUALIFIER:
qualifier = entry.getElementValuePairs()[0].getValue().stringifyValue();
break;
}
}
if (hasAutowired) {
WiringType wt = new WiringType(field.getSignature(), field.getGenericSignature(), qualifier);
FieldAnnotation existingAnnotation = wiredFields.get(wt);
if (existingAnnotation == null) {
wiredFields.put(wt, FieldAnnotation.fromBCELField(cls.getClassName(), field));
} else {
bugReporter.reportBug(new BugInstance(this, BugType.WI_DUPLICATE_WIRED_TYPES.name(), NORMAL_PRIORITY).addClass(cls).addField(FieldAnnotation.fromBCELField(cls, field)).addField(existingAnnotation));
wiredFields.remove(wt);
}
}
}
}
stack = new OpcodeStack();
super.visitClassContext(classContext);
} catch (ClassNotFoundException e) {
bugReporter.reportMissingClass(e);
} finally {
stack = null;
}
}
Aggregations