use of org.apache.bcel.classfile.Method 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.Method in project fb-contrib by mebigfatguy.
the class ListIndexedIterating method visitCode.
/**
* overrides the visitor to reset the opcode stack
*
* @param obj
* the code object for the currently parsed Code
*/
@Override
public void visitCode(final Code obj) {
Method m = getMethod();
if (prescreen(m)) {
sawListSize = false;
stack.resetForMethodEntry(this);
state = State.SAW_NOTHING;
stage = Stage.FIND_LOOP_STAGE;
super.visitCode(obj);
if (sawListSize && !possibleForLoops.isEmpty()) {
stack.resetForMethodEntry(this);
state = State.SAW_NOTHING;
stage = Stage.FIND_BUG_STAGE;
super.visitCode(obj);
}
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class ConfusingFunctionSemantics method visitCode.
/**
* implements the visitor to look for any non-immutable typed parameters are assignable to the return type. If found, the method is parsed.
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
try {
possibleParmRegs.clear();
Method m = getMethod();
String methodSignature = m.getSignature();
String retSignature = SignatureUtils.getReturnSignature(methodSignature);
JavaClass returnClass = null;
int[] parmRegs = null;
if (retSignature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) && !knownImmutables.contains(retSignature)) {
List<String> parmTypes = SignatureUtils.getParameterSignatures(methodSignature);
for (int p = 0; p < parmTypes.size(); p++) {
String parmSignature = parmTypes.get(p);
if (parmSignature.startsWith(Values.SIG_QUALIFIED_CLASS_PREFIX) && !knownImmutables.contains(parmSignature)) {
if (returnClass == null) {
returnClass = Repository.lookupClass(SignatureUtils.trimSignature(retSignature));
parmRegs = RegisterUtils.getParameterRegisters(m);
}
if (parmRegs != null) {
JavaClass parmClass = Repository.lookupClass(SignatureUtils.stripSignature(parmSignature));
if (parmClass.instanceOf(returnClass)) {
possibleParmRegs.put(Integer.valueOf(parmRegs[p]), new ParmUsage());
}
}
}
}
if (!possibleParmRegs.isEmpty()) {
try {
stack.resetForMethodEntry(this);
super.visitCode(obj);
for (ParmUsage pu : possibleParmRegs.values()) {
if ((pu.returnPC >= 0) && (pu.alteredPC >= 0) && (pu.returnPC > pu.alteredPC)) {
bugReporter.reportBug(new BugInstance(this, BugType.CFS_CONFUSING_FUNCTION_SEMANTICS.name(), NORMAL_PRIORITY).addClass(this).addMethod(this).addSourceLine(this, pu.returnPC).addSourceLine(this, pu.alteredPC));
}
}
} catch (StopOpcodeParsingException e) {
// no parm regs left
}
}
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class CopiedOverriddenMethod method visitClassContext.
/**
* overrides the visitor to accept classes derived from non java.lang.Object classes.
*
* @param clsContext
* the context object of the currently parsed class
*/
@Override
public void visitClassContext(ClassContext clsContext) {
try {
JavaClass cls = clsContext.getJavaClass();
String superName = cls.getSuperclassName();
if (!Values.DOTTED_JAVA_LANG_OBJECT.equals(superName)) {
this.classContext = clsContext;
superclassCode = new HashMap<>();
JavaClass superCls = cls.getSuperClass();
childPoolGen = new ConstantPoolGen(cls.getConstantPool());
parentPoolGen = new ConstantPoolGen(superCls.getConstantPool());
Method[] methods = superCls.getMethods();
for (Method m : methods) {
String methodName = m.getName();
if (m.isPublic() && !m.isAbstract() && !m.isSynthetic() && !Values.CONSTRUCTOR.equals(methodName) && !Values.STATIC_INITIALIZER.equals(methodName)) {
String methodInfo = methodName + ':' + m.getSignature();
superclassCode.put(methodInfo, new CodeInfo(m.getCode(), m.getAccessFlags()));
}
}
cls.accept(this);
}
} catch (ClassNotFoundException cnfe) {
bugReporter.reportMissingClass(cnfe);
} finally {
superclassCode = null;
this.classContext = null;
childPoolGen = null;
parentPoolGen = null;
}
}
use of org.apache.bcel.classfile.Method in project fb-contrib by mebigfatguy.
the class NonOwnedSynchronization method visitCode.
/**
* implements the visitor to reset the opcode stack
*
* @param obj
* the context object of the currently parsed code block
*/
@Override
public void visitCode(Code obj) {
Method method = getMethod();
if (prescreen(method)) {
stack.resetForMethodEntry(this);
regPriorities.clear();
int[] parmRegs = RegisterUtils.getParameterRegisters(method);
for (int reg : parmRegs) {
regPriorities.put(Integer.valueOf(reg), Values.NORMAL_BUG_PRIORITY);
}
if (!method.isStatic()) {
regPriorities.put(Values.ZERO, Values.LOW_BUG_PRIORITY);
}
super.visitCode(obj);
}
}
Aggregations