Java Code Examples for org.apache.bcel.classfile.Field#getAnnotationEntries()

The following examples show how to use org.apache.bcel.classfile.Field#getAnnotationEntries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnsafeJacksonDeserializationDetector.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void analyzeField(Field field, JavaClass javaClass) {
    for (AnnotationEntry annotation : field.getAnnotationEntries())  {
        if (ANNOTATION_TYPES.contains(annotation.getAnnotationType()) ||
                annotation.getAnnotationType().contains("JsonTypeInfo")) {
            for (ElementValuePair elementValuePair : annotation.getElementValuePairs()) {
                if ("use".equals((elementValuePair.getNameString())) &&
                        VULNERABLE_USE_NAMES.contains(elementValuePair.getValue().stringifyValue())) {
                    bugReporter.reportBug(new BugInstance(this, DESERIALIZATION_TYPE, HIGH_PRIORITY)
                            .addClass(javaClass)
                            .addString(javaClass.getClassName() + " on field " +
                                    field.getName() + " of type " + field.getType() +
                                    " annotated with " + annotation.toShortString())
                            .addField(FieldAnnotation.fromBCELField(javaClass, field))
                            .addString("")
                    );
                }
            }
        }
    }
}
 
Example 2
Source File: FieldAnnotationsTestCase.java    From commons-bcel with Apache License 2.0 5 votes vote down vote up
public void checkAnnotatedField(final JavaClass clazz, final String fieldname,
        final String AnnotationEntryName, final String AnnotationEntryElementName,
        final String AnnotationEntryElementValue)
{
    final Field[] fields = clazz.getFields();
    for (final Field f : fields) {
        final AnnotationEntry[] fieldAnnotationEntrys = f.getAnnotationEntries();
        if (f.getName().equals(fieldname))
        {
            checkAnnotationEntry(fieldAnnotationEntrys[0], AnnotationEntryName,
                    AnnotationEntryElementName, AnnotationEntryElementValue);
        }
    }
}