src.main.java.com.mebigfatguy.fbcontrib.detect.SyncCollectionIterators Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sb-contrib Show documentation
Show all versions of sb-contrib Show documentation
An auxiliary findbugs.sourceforge.net plugin for java bug detectors that fall outside the narrow scope of detectors to be packaged with the product itself.
The newest version!
/*
* fb-contrib - Auxiliary detectors for Java programs
* Copyright (C) 2005-2019 Dave Brosius
*
* 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.ArrayList;
import java.util.BitSet;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.apache.bcel.Const;
import org.apache.bcel.classfile.Code;
import org.apache.bcel.classfile.ConstantFieldref;
import org.apache.bcel.classfile.ConstantNameAndType;
import com.mebigfatguy.fbcontrib.utils.OpcodeUtils;
import com.mebigfatguy.fbcontrib.utils.RegisterUtils;
import com.mebigfatguy.fbcontrib.utils.UnmodifiableSet;
import com.mebigfatguy.fbcontrib.utils.Values;
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.XField;
/**
* Looks for use of iterators on synchronized collections built from the
* Collections class. As the collection in question was built thru
* Collections.synchronizedXXX, an assumption is made that this collection must
* be multithreaded safe. However, iterator access is used, which is explicitly
* unsafe. When iterators are to be used, synchronization should be done
* manually.
*/
public class SyncCollectionIterators extends BytecodeScanningDetector {
private static final Set synchCollectionNames = UnmodifiableSet.create("synchronizedSet", "synchronizedMap",
"synchronizedList", "synchronizedSortedSet", "synchronizedSortedMap");
private static final Set mapToSetMethods = UnmodifiableSet.create("keySet", "entrySet", "values");
enum State {
SEEN_NOTHING, SEEN_SYNC, SEEN_LOAD
}
private final BugReporter bugReporter;
private State state;
private Set memberCollections;
private BitSet localCollections;
private List