<commit_before>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003,2004 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs.detect;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;

import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Attribute;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.ConstantValue;
import org.apache.bcel.classfile.ElementValue;
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.generic.ObjectType;
import org.apache.bcel.generic.ReferenceType;
import org.apache.bcel.generic.Type;

import edu.umd.cs.findbugs.BugAccumulator;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.DeepSubtypeAnalysis;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ProgramPoint;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.SystemProperties;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.XClass;
import edu.umd.cs.findbugs.ba.XFactory;
import edu.umd.cs.findbugs.ba.XField;
import edu.umd.cs.findbugs.ba.ch.Subtypes2;
import edu.umd.cs.findbugs.ba.generic.GenericObjectType;
import edu.umd.cs.findbugs.ba.generic.GenericUtilities;
import edu.umd.cs.findbugs.ba.npe.IsNullValue;
import edu.umd.cs.findbugs.ba.npe.IsNullValueDataflow;
import edu.umd.cs.findbugs.ba.npe.IsNullValueFrame;
import edu.umd.cs.findbugs.ba.vna.AvailableLoad;
import edu.umd.cs.findbugs.ba.vna.ValueNumber;
import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow;
import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.DescriptorFactory;
import edu.umd.cs.findbugs.classfile.FieldDescriptor;
import edu.umd.cs.findbugs.classfile.Global;
import edu.umd.cs.findbugs.internalAnnotations.DottedClassName;
import edu.umd.cs.findbugs.util.Bag;
import edu.umd.cs.findbugs.util.ClassName;
import edu.umd.cs.findbugs.util.MultiMap;
import edu.umd.cs.findbugs.util.Util;
import edu.umd.cs.findbugs.visitclass.PreorderVisitor;

public class UnreadFields extends OpcodeStackDetector {
    private static final boolean DEBUG = SystemProperties.getBoolean("unreadfields.debug");

    public boolean isContainerField(XField f) {
        return containerFields.contains(f);
    }

    Map<XField, Set<ProgramPoint>> assumedNonNull = new HashMap<XField, Set<ProgramPoint>>();

    Map<XField, ProgramPoint> threadLocalAssignedInConstructor = new HashMap<XField, ProgramPoint>();

    Set<XField> nullTested = new HashSet<XField>();

    Set<XField> containerFields = new TreeSet<XField>();

    MultiMap<XField, String> unknownAnnotation = new MultiMap<XField, String>(LinkedList.class);

    Set<String> abstractClasses = new HashSet<String>();

    Set<String> hasNonAbstractSubClass = new HashSet<String>();

    Set<String> classesScanned = new HashSet<String>();

    Set<XField> fieldsOfNativeClasses = new HashSet<XField>();

    Set<XField> reflectiveFields = new HashSet<XField>();

    Set<XField> fieldsOfSerializableOrNativeClassed = new HashSet<XField>();

    Set<XField> staticFieldsReadInThisMethod = new HashSet<XField>();

    Set<XField> allMyFields = new TreeSet<XField>();

    Set<XField> myFields = new TreeSet<XField>();

    Set<XField> writtenFields = new HashSet<XField>();

    /**
     * Only for fields that are either: * read only * written only * written
     * null and read
     */
    Map<XField, SourceLineAnnotation> fieldAccess = new HashMap<XField, SourceLineAnnotation>();

    Set<XField> writtenNonNullFields = new HashSet<XField>();

    Set<String> calledFromConstructors = new HashSet<String>();

    Set<XField> writtenInConstructorFields = new HashSet<XField>();

    Set<XField> writtenInInitializationFields = new HashSet<XField>();

    Set<XField> writtenOutsideOfInitializationFields = new HashSet<XField>();

    Set<XField> readFields = new HashSet<XField>();

    Set<XField> constantFields = new HashSet<XField>();

    Set<String> needsOuterObjectInConstructor = new HashSet<String>();

    Set<String> innerClassCannotBeStatic = new HashSet<String>();

    boolean hasNativeMethods;

    boolean isSerializable;

    boolean sawSelfCallInConstructor;

    private final BugReporter bugReporter;

    private final BugAccumulator bugAccumulator;

    boolean publicOrProtectedConstructor;

    public Set<? extends XField> getReadFields() {
        return readFields;
    }

    public Set<? extends XField> getWrittenFields() {
        return writtenFields;
    }

    public boolean isWrittenOutsideOfInitialization(XField f) {
        return writtenOutsideOfInitializationFields.contains(f);
    }

    public boolean isWrittenDuringInitialization(XField f) {
        return writtenInInitializationFields.contains(f);
    }

    public boolean isWrittenInConstructor(XField f) {
        return writtenInConstructorFields.contains(f);
    }

    static final int doNotConsider = ACC_PUBLIC | ACC_PROTECTED;

    ClassDescriptor externalizable = DescriptorFactory.createClassDescriptor(java.io.Externalizable.class);

    ClassDescriptor serializable = DescriptorFactory.createClassDescriptor(java.io.Serializable.class);

    ClassDescriptor remote = DescriptorFactory.createClassDescriptor(java.rmi.Remote.class);

    public UnreadFields(BugReporter bugReporter) {
        this.bugReporter = bugReporter;
        this.bugAccumulator = new BugAccumulator(bugReporter);
        AnalysisContext context = AnalysisContext.currentAnalysisContext();
        reflectiveFields.add( XFactory.createXField("java.lang.System", "in", "Ljava/io/InputStream;", true));
        reflectiveFields.add( XFactory.createXField("java.lang.System", "out", "Ljava/io/PrintStream;", true));
        reflectiveFields.add( XFactory.createXField("java.lang.System", "err", "Ljava/io/PrintStream;", true));
        context.setUnreadFields(this);
    }

    HashSet<ClassDescriptor> toldStrongEvidenceForIntendedSerialization = new HashSet<ClassDescriptor>();

    public void strongEvidenceForIntendedSerialization(ClassDescriptor c) {
        toldStrongEvidenceForIntendedSerialization.add(c);
    }

    public boolean existsStrongEvidenceForIntendedSerialization(ClassDescriptor c) {
        return toldStrongEvidenceForIntendedSerialization.contains(c);
    }

    @Override
    public void visit(JavaClass obj) {
        calledFromConstructors.clear();
        hasNativeMethods = false;
        sawSelfCallInConstructor = false;
        publicOrProtectedConstructor = false;
        isSerializable = false;
        if (obj.isAbstract()) {
            abstractClasses.add(getDottedClassName());
        } else {
            String superClass = obj.getSuperclassName();
            if (superClass != null)
                hasNonAbstractSubClass.add(superClass);
        }
        classesScanned.add(getDottedClassName());
        boolean superClassIsObject = "java.lang.Object".equals(obj.getSuperclassName());
        if (getSuperclassName().indexOf("$") >= 0 || getSuperclassName().indexOf("+") >= 0
                || withinAnonymousClass.matcher(getDottedClassName()).find()) {
            // System.out.println("hicfsc: " + betterClassName);
            innerClassCannotBeStatic.add(getDottedClassName());
            // System.out.println("hicfsc: " + betterSuperclassName);
            innerClassCannotBeStatic.add(getDottedSuperclassName());
        }
        // Does this class directly implement Serializable?
        String[] interface_names = obj.getInterfaceNames();
        for (String interface_name : interface_names) {
            if (interface_name.equals("java.io.Externalizable")) {
                isSerializable = true;
            } else if (interface_name.equals("java.io.Serializable")) {
                isSerializable = true;
                break;
            }
        }

        // Does this class indirectly implement Serializable?
        if ((!superClassIsObject || interface_names.length > 0) && !isSerializable) {
            try {
                Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
                ClassDescriptor desc = DescriptorFactory.createClassDescriptor(obj);
                if (subtypes2.getSubtypes(serializable).contains(desc) || subtypes2.getSubtypes(externalizable).contains(desc)
                        || subtypes2.getSubtypes(remote).contains(desc)) {
                    isSerializable = true;
                }
            } catch (ClassNotFoundException e) {
                bugReporter.reportMissingClass(e);
            }
        }

        // System.out.println(getDottedClassName() + " is serializable: " +
        // isSerializable);
        super.visit(obj);
    }

    public static boolean classHasParameter(JavaClass obj) {
        for (Attribute a : obj.getAttributes())
            if (a instanceof Signature) {
                String sig = ((Signature) a).getSignature();
                return sig.charAt(0) == '<';
            }
        return false;
    }

    @Override
    public void visitAfter(JavaClass obj) {
        if (hasNativeMethods) {
            fieldsOfSerializableOrNativeClassed.addAll(myFields);
            fieldsOfNativeClasses.addAll(myFields);
        }
        if (isSerializable) {
            fieldsOfSerializableOrNativeClassed.addAll(myFields);
        }
        if (sawSelfCallInConstructor) {
            myFields.removeAll(writtenInConstructorFields);
            writtenInInitializationFields.addAll(myFields);
        }
        myFields.clear();
        allMyFields.clear();
        calledFromConstructors.clear();
    }

    @Override
    public void visit(Field obj) {
        super.visit(obj);
        XField f = XFactory.createXField(this);
        allMyFields.add(f);
        String signature = obj.getSignature();
        if (!getFieldName().equals("serialVersionUID")) {

            myFields.add(f);
            if (obj.getName().equals("_jspx_dependants"))
                containerFields.add(f);
        }
        if (isSeleniumWebElement(signature))
            containerFields.add(f);
    }

    /**
     * @param signature
     * @return
     */
    public static boolean isSeleniumWebElement(String signature) {
        return signature.equals("Lorg/openqa/selenium/RenderedWebElement;")
                || signature.equals("Lorg/openqa/selenium/WebElement;");
    }

    @Override
    public void visitAnnotation(String annotationClass, Map<String, ElementValue> map, boolean runtimeVisible) {
        if (!visitingField())
            return;
        if (isInjectionAttribute(annotationClass)) {
            containerFields.add(XFactory.createXField(this));
        }
        if (!annotationClass.startsWith("edu.umd.cs.findbugs") && !annotationClass.startsWith("javax.lang"))
            unknownAnnotation.add(XFactory.createXField(this), annotationClass);

    }

    public static boolean isInjectionAttribute(@DottedClassName String annotationClass) {
        if (annotationClass.startsWith("javax.annotation.") || annotationClass.startsWith("javax.ejb")
                || annotationClass.equals("org.apache.tapestry5.annotations.Persist")
                || annotationClass.equals("org.jboss.seam.annotations.In") || annotationClass.startsWith("javax.persistence")
                || annotationClass.endsWith("SpringBean") || annotationClass.equals("com.google.inject.Inject")
                || annotationClass.startsWith("com.google.") && annotationClass.endsWith(".Bind")
                && annotationClass.hashCode() == -243168318 || annotationClass.startsWith("org.nuxeo.common.xmap.annotation")
                || annotationClass.startsWith("com.google.gwt.uibinder.client")
                || annotationClass.startsWith("org.springframework.beans.factory.annotation"))
            return true;
        int lastDot = annotationClass.lastIndexOf('.');
        String lastPart = annotationClass.substring(lastDot + 1);
        if (lastPart.startsWith("Inject"))
            return true;
        return false;
    }

    @Override
    public void visit(ConstantValue obj) {
        // ConstantValue is an attribute of a field, so the instance variables
        // set during visitation of the Field are still valid here
        XField f = XFactory.createXField(this);
        constantFields.add(f);
    }

    int count_aload_1;

    private int previousOpcode;

    private int previousPreviousOpcode;

    @Override
    public void visit(Code obj) {

        count_aload_1 = 0;
        previousOpcode = -1;<commit_msg>Add javax.ws.rs.core.Context to list of injection annotations<commit_after>/*
 * FindBugs - Find bugs in Java programs
 * Copyright (C) 2003,2004 University of Maryland
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package edu.umd.cs.findbugs.detect;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;

import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Attribute;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.ConstantValue;
import org.apache.bcel.classfile.ElementValue;
import org.apache.bcel.classfile.Field;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;
import org.apache.bcel.classfile.Signature;
import org.apache.bcel.generic.ObjectType;
import org.apache.bcel.generic.ReferenceType;
import org.apache.bcel.generic.Type;

import edu.umd.cs.findbugs.BugAccumulator;
import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.DeepSubtypeAnalysis;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ProgramPoint;
import edu.umd.cs.findbugs.SourceLineAnnotation;
import edu.umd.cs.findbugs.SystemProperties;
import edu.umd.cs.findbugs.ba.AnalysisContext;
import edu.umd.cs.findbugs.ba.XClass;
import edu.umd.cs.findbugs.ba.XFactory;
import edu.umd.cs.findbugs.ba.XField;
import edu.umd.cs.findbugs.ba.ch.Subtypes2;
import edu.umd.cs.findbugs.ba.generic.GenericObjectType;
import edu.umd.cs.findbugs.ba.generic.GenericUtilities;
import edu.umd.cs.findbugs.ba.npe.IsNullValue;
import edu.umd.cs.findbugs.ba.npe.IsNullValueDataflow;
import edu.umd.cs.findbugs.ba.npe.IsNullValueFrame;
import edu.umd.cs.findbugs.ba.vna.AvailableLoad;
import edu.umd.cs.findbugs.ba.vna.ValueNumber;
import edu.umd.cs.findbugs.ba.vna.ValueNumberDataflow;
import edu.umd.cs.findbugs.ba.vna.ValueNumberFrame;
import edu.umd.cs.findbugs.bcel.OpcodeStackDetector;
import edu.umd.cs.findbugs.classfile.CheckedAnalysisException;
import edu.umd.cs.findbugs.classfile.ClassDescriptor;
import edu.umd.cs.findbugs.classfile.DescriptorFactory;
import edu.umd.cs.findbugs.classfile.FieldDescriptor;
import edu.umd.cs.findbugs.classfile.Global;
import edu.umd.cs.findbugs.internalAnnotations.DottedClassName;
import edu.umd.cs.findbugs.util.Bag;
import edu.umd.cs.findbugs.util.ClassName;
import edu.umd.cs.findbugs.util.MultiMap;
import edu.umd.cs.findbugs.util.Util;
import edu.umd.cs.findbugs.visitclass.PreorderVisitor;

public class UnreadFields extends OpcodeStackDetector {
    private static final boolean DEBUG = SystemProperties.getBoolean("unreadfields.debug");

    public boolean isContainerField(XField f) {
        return containerFields.contains(f);
    }

    Map<XField, Set<ProgramPoint>> assumedNonNull = new HashMap<XField, Set<ProgramPoint>>();

    Map<XField, ProgramPoint> threadLocalAssignedInConstructor = new HashMap<XField, ProgramPoint>();

    Set<XField> nullTested = new HashSet<XField>();

    Set<XField> containerFields = new TreeSet<XField>();

    MultiMap<XField, String> unknownAnnotation = new MultiMap<XField, String>(LinkedList.class);

    Set<String> abstractClasses = new HashSet<String>();

    Set<String> hasNonAbstractSubClass = new HashSet<String>();

    Set<String> classesScanned = new HashSet<String>();

    Set<XField> fieldsOfNativeClasses = new HashSet<XField>();

    Set<XField> reflectiveFields = new HashSet<XField>();

    Set<XField> fieldsOfSerializableOrNativeClassed = new HashSet<XField>();

    Set<XField> staticFieldsReadInThisMethod = new HashSet<XField>();

    Set<XField> allMyFields = new TreeSet<XField>();

    Set<XField> myFields = new TreeSet<XField>();

    Set<XField> writtenFields = new HashSet<XField>();

    /**
     * Only for fields that are either: * read only * written only * written
     * null and read
     */
    Map<XField, SourceLineAnnotation> fieldAccess = new HashMap<XField, SourceLineAnnotation>();

    Set<XField> writtenNonNullFields = new HashSet<XField>();

    Set<String> calledFromConstructors = new HashSet<String>();

    Set<XField> writtenInConstructorFields = new HashSet<XField>();

    Set<XField> writtenInInitializationFields = new HashSet<XField>();

    Set<XField> writtenOutsideOfInitializationFields = new HashSet<XField>();

    Set<XField> readFields = new HashSet<XField>();

    Set<XField> constantFields = new HashSet<XField>();

    Set<String> needsOuterObjectInConstructor = new HashSet<String>();

    Set<String> innerClassCannotBeStatic = new HashSet<String>();

    boolean hasNativeMethods;

    boolean isSerializable;

    boolean sawSelfCallInConstructor;

    private final BugReporter bugReporter;

    private final BugAccumulator bugAccumulator;

    boolean publicOrProtectedConstructor;

    public Set<? extends XField> getReadFields() {
        return readFields;
    }

    public Set<? extends XField> getWrittenFields() {
        return writtenFields;
    }

    public boolean isWrittenOutsideOfInitialization(XField f) {
        return writtenOutsideOfInitializationFields.contains(f);
    }

    public boolean isWrittenDuringInitialization(XField f) {
        return writtenInInitializationFields.contains(f);
    }

    public boolean isWrittenInConstructor(XField f) {
        return writtenInConstructorFields.contains(f);
    }

    static final int doNotConsider = ACC_PUBLIC | ACC_PROTECTED;

    ClassDescriptor externalizable = DescriptorFactory.createClassDescriptor(java.io.Externalizable.class);

    ClassDescriptor serializable = DescriptorFactory.createClassDescriptor(java.io.Serializable.class);

    ClassDescriptor remote = DescriptorFactory.createClassDescriptor(java.rmi.Remote.class);

    public UnreadFields(BugReporter bugReporter) {
        this.bugReporter = bugReporter;
        this.bugAccumulator = new BugAccumulator(bugReporter);
        AnalysisContext context = AnalysisContext.currentAnalysisContext();
        reflectiveFields.add( XFactory.createXField("java.lang.System", "in", "Ljava/io/InputStream;", true));
        reflectiveFields.add( XFactory.createXField("java.lang.System", "out", "Ljava/io/PrintStream;", true));
        reflectiveFields.add( XFactory.createXField("java.lang.System", "err", "Ljava/io/PrintStream;", true));
        context.setUnreadFields(this);
    }

    HashSet<ClassDescriptor> toldStrongEvidenceForIntendedSerialization = new HashSet<ClassDescriptor>();

    public void strongEvidenceForIntendedSerialization(ClassDescriptor c) {
        toldStrongEvidenceForIntendedSerialization.add(c);
    }

    public boolean existsStrongEvidenceForIntendedSerialization(ClassDescriptor c) {
        return toldStrongEvidenceForIntendedSerialization.contains(c);
    }

    @Override
    public void visit(JavaClass obj) {
        calledFromConstructors.clear();
        hasNativeMethods = false;
        sawSelfCallInConstructor = false;
        publicOrProtectedConstructor = false;
        isSerializable = false;
        if (obj.isAbstract()) {
            abstractClasses.add(getDottedClassName());
        } else {
            String superClass = obj.getSuperclassName();
            if (superClass != null)
                hasNonAbstractSubClass.add(superClass);
        }
        classesScanned.add(getDottedClassName());
        boolean superClassIsObject = "java.lang.Object".equals(obj.getSuperclassName());
        if (getSuperclassName().indexOf("$") >= 0 || getSuperclassName().indexOf("+") >= 0
                || withinAnonymousClass.matcher(getDottedClassName()).find()) {
            // System.out.println("hicfsc: " + betterClassName);
            innerClassCannotBeStatic.add(getDottedClassName());
            // System.out.println("hicfsc: " + betterSuperclassName);
            innerClassCannotBeStatic.add(getDottedSuperclassName());
        }
        // Does this class directly implement Serializable?
        String[] interface_names = obj.getInterfaceNames();
        for (String interface_name : interface_names) {
            if (interface_name.equals("java.io.Externalizable")) {
                isSerializable = true;
            } else if (interface_name.equals("java.io.Serializable")) {
                isSerializable = true;
                break;
            }
        }

        // Does this class indirectly implement Serializable?
        if ((!superClassIsObject || interface_names.length > 0) && !isSerializable) {
            try {
                Subtypes2 subtypes2 = AnalysisContext.currentAnalysisContext().getSubtypes2();
                ClassDescriptor desc = DescriptorFactory.createClassDescriptor(obj);
                if (subtypes2.getSubtypes(serializable).contains(desc) || subtypes2.getSubtypes(externalizable).contains(desc)
                        || subtypes2.getSubtypes(remote).contains(desc)) {
                    isSerializable = true;
                }
            } catch (ClassNotFoundException e) {
                bugReporter.reportMissingClass(e);
            }
        }

        // System.out.println(getDottedClassName() + " is serializable: " +
        // isSerializable);
        super.visit(obj);
    }

    public static boolean classHasParameter(JavaClass obj) {
        for (Attribute a : obj.getAttributes())
            if (a instanceof Signature) {
                String sig = ((Signature) a).getSignature();
                return sig.charAt(0) == '<';
            }
        return false;
    }

    @Override
    public void visitAfter(JavaClass obj) {
        if (hasNativeMethods) {
            fieldsOfSerializableOrNativeClassed.addAll(myFields);
            fieldsOfNativeClasses.addAll(myFields);
        }
        if (isSerializable) {
            fieldsOfSerializableOrNativeClassed.addAll(myFields);
        }
        if (sawSelfCallInConstructor) {
            myFields.removeAll(writtenInConstructorFields);
            writtenInInitializationFields.addAll(myFields);
        }
        myFields.clear();
        allMyFields.clear();
        calledFromConstructors.clear();
    }

    @Override
    public void visit(Field obj) {
        super.visit(obj);
        XField f = XFactory.createXField(this);
        allMyFields.add(f);
        String signature = obj.getSignature();
        if (!getFieldName().equals("serialVersionUID")) {

            myFields.add(f);
            if (obj.getName().equals("_jspx_dependants"))
                containerFields.add(f);
        }
        if (isSeleniumWebElement(signature))
            containerFields.add(f);
    }

    /**
     * @param signature
     * @return
     */
    public static boolean isSeleniumWebElement(String signature) {
        return signature.equals("Lorg/openqa/selenium/RenderedWebElement;")
                || signature.equals("Lorg/openqa/selenium/WebElement;");
    }

    @Override
    public void visitAnnotation(String annotationClass, Map<String, ElementValue> map, boolean runtimeVisible) {
        if (!visitingField())
            return;
        if (isInjectionAttribute(annotationClass)) {
            containerFields.add(XFactory.createXField(this));
        }
        if (!annotationClass.startsWith("edu.umd.cs.findbugs") && !annotationClass.startsWith("javax.lang"))
            unknownAnnotation.add(XFactory.createXField(this), annotationClass);

    }

    public static boolean isInjectionAttribute(@DottedClassName String annotationClass) {
        if (annotationClass.startsWith("javax.annotation.")
                || annotationClass.startsWith("javax.ejb")
                || annotationClass.equals("org.apache.tapestry5.annotations.Persist")
                || annotationClass.equals("org.jboss.seam.annotations.In")
                || annotationClass.startsWith("javax.persistence")
                || annotationClass.endsWith("SpringBean")
                || annotationClass.equals("com.google.inject.Inject")
                || annotationClass.startsWith("com.google.") && annotationClass.endsWith(".Bind")
                && annotationClass.hashCode() == -243168318
                || annotationClass.startsWith("org.nuxeo.common.xmap.annotation")
                || annotationClass.startsWith("com.google.gwt.uibinder.client")
                || annotationClass.startsWith("org.springframework.beans.factory.annotation")
                || annotationClass.equals("javax.ws.rs.core.Context"))
            return true;
        int lastDot = annotationClass.lastIndexOf('.');
        String lastPart = annotationClass.substring(lastDot + 1);
        if (lastPart.startsWith("Inject"))
            return true;
        return false;
    }

    @Override
    public void visit(ConstantValue obj) {
        // ConstantValue is an attribute of a field, so the instance variables
        // set during visitation of the Field are still valid here
        XField f = XFactory.createXField(this);
        constantFields.add(f);
    }

    int count_aload_1;

    private int previousOpcode;

    private int previousPreviousOpcode;

    @Override
    public void visit(Code obj) {

        count_aload_1 = 0;
        previousOpcode = -1;
{'fraction_non_alphanumeric': 0.10499963979540379, 'fraction_numerical': 0.0036020459621064764, 'mean_word_length': 3.354297365119197, 'pattern_counts': {'":': 0, '<': 119, '<?xml version=': 0, '>': 123, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6986273', 'n_tokens_mistral': 8098, 'n_tokens_neox': 7748, 'n_words': 1528}