<commit_before>/*
 * fb-contrib - Auxiliary detectors for Java programs
 * Copyright (C) 2005-2015 <NAME>
 * 
 * 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 com.mebigfatguy.fbcontrib.detect;

import java.util.BitSet;
import java.util.HashSet;
import java.util.Set;

import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantInteger;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;

import com.mebigfatguy.fbcontrib.utils.BugType;

import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XMethod;

/**
 * looks for methods that access arrays or classes that implement java.util.List
 * using a constant integer for the index. This is often a typo intented to be a
 * loop variable, but if specific indices mean certain things, perhaps a first
 * class object would be a better choice for a container.
 */
public class ConstantListIndex extends BytecodeScanningDetector {
    enum State {
        SAW_NOTHING, SAW_CONSTANT_0, SAW_CONSTANT
    }

    private static final String MAX_ICONST0_LOOP_DISTANCE_PROPERTY = "fb-contrib.cli.maxloopdistance";
    private static final Set<String> ubiquitousMethods = new HashSet<String>(2);
    private static JavaClass INVOCATIONHANDLER_CLASS;

    static {
        ubiquitousMethods.add("java.lang.String.split(Ljava/lang/String;)[Ljava/lang/String;");

        try {
            INVOCATIONHANDLER_CLASS = Repository.lookupClass("java/lang/reflect/InvocationHandler");
        } catch (ClassNotFoundException cnfe) {
            INVOCATIONHANDLER_CLASS = null;
        }
    }

    private final BugReporter bugReporter;
    private State state;
    private BitSet iConst0Looped;
    private final int max_iConst0LoopDistance;
    private OpcodeStack stack;

    /**
     * constructs a CLI detector given the reporter to report bugs on
     * 
     * @param bugReporter
     *            the sync of bug reports
     */
    public ConstantListIndex(BugReporter bugReporter) {
        this.bugReporter = bugReporter;
        max_iConst0LoopDistance = Integer.getInteger(MAX_ICONST0_LOOP_DISTANCE_PROPERTY, 30).intValue();<commit_msg>ignore String.split that takes a second parm for CSI<commit_after>/*
 * fb-contrib - Auxiliary detectors for Java programs
 * Copyright (C) 2005-2015 <NAME>
 * 
 * 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 com.mebigfatguy.fbcontrib.detect;

import java.util.BitSet;
import java.util.HashSet;
import java.util.Set;

import org.apache.bcel.Repository;
import org.apache.bcel.classfile.Constant;
import org.apache.bcel.classfile.ConstantInteger;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.classfile.Method;

import com.mebigfatguy.fbcontrib.utils.BugType;

import edu.umd.cs.findbugs.BugInstance;
import edu.umd.cs.findbugs.BugReporter;
import edu.umd.cs.findbugs.BytecodeScanningDetector;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.ba.ClassContext;
import edu.umd.cs.findbugs.ba.XMethod;

/**
 * looks for methods that access arrays or classes that implement java.util.List
 * using a constant integer for the index. This is often a typo intented to be a
 * loop variable, but if specific indices mean certain things, perhaps a first
 * class object would be a better choice for a container.
 */
public class ConstantListIndex extends BytecodeScanningDetector {
    enum State {
        SAW_NOTHING, SAW_CONSTANT_0, SAW_CONSTANT
    }

    private static final String MAX_ICONST0_LOOP_DISTANCE_PROPERTY = "fb-contrib.cli.maxloopdistance";
    private static final Set<String> ubiquitousMethods = new HashSet<String>(2);
    private static JavaClass INVOCATIONHANDLER_CLASS;

    static {
        ubiquitousMethods.add("java.lang.String.split(Ljava/lang/String;)[Ljava/lang/String;");
        ubiquitousMethods.add("java.lang.String.split(Ljava/lang/String;I)[Ljava/lang/String;");

        try {
            INVOCATIONHANDLER_CLASS = Repository.lookupClass("java/lang/reflect/InvocationHandler");
        } catch (ClassNotFoundException cnfe) {
            INVOCATIONHANDLER_CLASS = null;
        }
    }

    private final BugReporter bugReporter;
    private State state;
    private BitSet iConst0Looped;
    private final int max_iConst0LoopDistance;
    private OpcodeStack stack;

    /**
     * constructs a CLI detector given the reporter to report bugs on
     * 
     * @param bugReporter
     *            the sync of bug reports
     */
    public ConstantListIndex(BugReporter bugReporter) {
        this.bugReporter = bugReporter;
        max_iConst0LoopDistance = Integer.getInteger(MAX_ICONST0_LOOP_DISTANCE_PROPERTY, 30).intValue();
{'fraction_non_alphanumeric': 0.07614942528735633, 'fraction_numerical': 0.01053639846743295, 'mean_word_length': 3.7934200459066565, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '2012343', 'n_tokens_mistral': 1914, 'n_tokens_neox': 1812, 'n_words': 584}