code
stringlengths
73
34.1k
label
stringclasses
1 value
public InnerClassAccess getInnerClassAccess(INVOKESTATIC inv, ConstantPoolGen cpg) throws ClassNotFoundException { String methodName = inv.getMethodName(cpg); if (methodName.startsWith("access$")) { String className = inv.getClassName(cpg); return getInnerClassAccess(className, ...
java
private Map<String, InnerClassAccess> getAccessMapForClass(String className) throws ClassNotFoundException { Map<String, InnerClassAccess> map = classToAccessMap.get(className); if (map == null) { map = new HashMap<>(3); if (!className.startsWith("[")) { JavaCla...
java
public int getMnemonic() { int mnemonic = KeyEvent.VK_UNDEFINED; if (!MAC_OS_X) { int index = getMnemonicIndex(); if ((index >= 0) && ((index + 1) < myAnnotatedString.length())) { mnemonic = Character.toUpperCase(myAnnotatedString.charAt(index + 1)); }...
java
public static void localiseButton(AbstractButton button, String key, String defaultString, boolean setMnemonic) { AnnotatedString as = new AnnotatedString(L10N.getLocalString(key, defaultString)); button.setText(as.toString()); int mnemonic; if (setMnemonic && (mnemonic = as.getMnemonic(...
java
public MethodHash computeHash(Method method) { final MessageDigest digest = Util.getMD5Digest(); byte[] code; if (method.getCode() == null || method.getCode().getCode() == null) { code = new byte[0]; } else { code = method.getCode().getCode(); } ...
java
static int compareGroups(BugGroup m1, BugGroup m2) { int result = m1.compareTo(m2); if (result == 0) { return m1.getShortDescription().compareToIgnoreCase(m2.getShortDescription()); } return result; }
java
static int compareMarkers(IMarker m1, IMarker m2) { if (m1 == null || m2 == null || !m1.exists() || !m2.exists()) { return 0; } int rank1 = MarkerUtil.findBugRankForMarker(m1); int rank2 = MarkerUtil.findBugRankForMarker(m2); int result = rank1 - rank2; if (re...
java
public void setParamsWithProperty(BitSet nonNullSet) { for (int i = 0; i < 32; ++i) { setParamWithProperty(i, nonNullSet.get(i)); } }
java
public void setParamWithProperty(int param, boolean hasProperty) { if (param < 0 || param > 31) { return; } if (hasProperty) { bits |= (1 << param); } else { bits &= ~(1 << param); } }
java
public BitSet getMatchingParameters(BitSet nullArgSet) { BitSet result = new BitSet(); for (int i = 0; i < 32; ++i) { result.set(i, nullArgSet.get(i) && hasProperty(i)); } return result; }
java
public static int getNumParametersForInvocation(InvokeInstruction inv, ConstantPoolGen cpg) { SignatureParser sigParser = new SignatureParser(inv.getSignature(cpg)); return sigParser.getNumParameters(); }
java
public void build() { int numGood = 0, numBytecodes = 0; if (DEBUG) { System.out.println("Method: " + methodGen.getName() + " - " + methodGen.getSignature() + "in class " + methodGen.getClassName()); } // Associate line number information with each Instr...
java
public void setReturnValue(MethodDescriptor methodDesc, TypeQualifierValue<?> tqv, TypeQualifierAnnotation tqa) { Map<TypeQualifierValue<?>, TypeQualifierAnnotation> map = returnValueMap.get(methodDesc); if (map == null) { map = new HashMap<>(); returnValueMap.put(methodDesc, map...
java
public TypeQualifierAnnotation getReturnValue(MethodDescriptor methodDesc, TypeQualifierValue<?> tqv) { // // TODO: handling of overridden methods? // Map<TypeQualifierValue<?>, TypeQualifierAnnotation> map = returnValueMap.get(methodDesc); if (map == null) { return n...
java
public void setParameter(MethodDescriptor methodDesc, int param, TypeQualifierValue<?> tqv, TypeQualifierAnnotation tqa) { Map<TypeQualifierValue<?>, TypeQualifierAnnotation> map = parameterMap.get(methodDesc, param); if (map == null) { map = new HashMap<>(); parameterMap.put(met...
java
public TypeQualifierAnnotation getParameter(MethodDescriptor methodDesc, int param, TypeQualifierValue<?> tqv) { // // TODO: handling of overridden methods? // Map<TypeQualifierValue<?>, TypeQualifierAnnotation> map = parameterMap.get(methodDesc, param); if (map == null) { ...
java
protected static boolean isLongOrDouble(FieldInstruction fieldIns, ConstantPoolGen cpg) { Type type = fieldIns.getFieldType(cpg); int code = type.getType(); return code == Const.T_LONG || code == Const.T_DOUBLE; }
java
protected static Variable snarfFieldValue(FieldInstruction fieldIns, ConstantPoolGen cpg, ValueNumberFrame frame) throws DataflowAnalysisException { if (isLongOrDouble(fieldIns, cpg)) { int numSlots = frame.getNumSlots(); ValueNumber topValue = frame.getValue(numSlots - 1); ...
java
public static Collection<TypeQualifierValue<?>> getRelevantTypeQualifiers(MethodDescriptor methodDescriptor, CFG cfg) throws CheckedAnalysisException { final HashSet<TypeQualifierValue<?>> result = new HashSet<>(); XMethod xmethod = XFactory.createXMethod(methodDescriptor); if (FI...
java
public static ClassDescriptor createClassDescriptorFromResourceName(String resourceName) { if (!isClassResource(resourceName)) { throw new IllegalArgumentException("Resource " + resourceName + " is not a class"); } return createClassDescriptor(resourceName.substring(0, resourceName.l...
java
public static @CheckForNull ClassDescriptor createClassDescriptorFromFieldSignature(String signature) { int start = signature.indexOf('L'); if (start < 0) { return null; } int end = signature.indexOf(';', start); if (end < 0) { return null; } ...
java
public void setPluginList(Path src) { if (pluginList == null) { pluginList = src; } else { pluginList.append(src); } }
java
public void addAllowedClass(String className) { String classRegex = START + dotsToRegex(className) + ".class$"; LOG.debug("Class regex: {}", classRegex); patternList.add(Pattern.compile(classRegex).matcher("")); }
java
public void addAllowedPackage(String packageName) { if (packageName.endsWith(".")) { packageName = packageName.substring(0, packageName.length() - 1); } String packageRegex = START + dotsToRegex(packageName) + SEP + JAVA_IDENTIFIER_PART + "+.class$"; LOG.debug("Package regex...
java
public void addAllowedPrefix(String prefix) { if (prefix.endsWith(".")) { prefix = prefix.substring(0, prefix.length() - 1); } LOG.debug("Allowed prefix: {}", prefix); String packageRegex = START + dotsToRegex(prefix) + SEP; LOG.debug("Prefix regex: {}", packageRegex)...
java
@Deprecated public @Nonnull String getMessage(String key) { BugPattern bugPattern = DetectorFactoryCollection.instance().lookupBugPattern(key); if (bugPattern == null) { return L10N.getLocalString("err.missing_pattern", "Error: missing bug pattern for key") + " " + key; } ...
java
public @Nonnull String getDetailHTML(String key) { BugPattern bugPattern = DetectorFactoryCollection.instance().lookupBugPattern(key); if (bugPattern == null) { return L10N.getLocalString("err.missing_pattern", "Error: missing bug pattern for key") + " " + key; } return b...
java
public String getAnnotationDescription(String key) { try { return annotationDescriptionBundle.getString(key); } catch (MissingResourceException mre) { if (DEBUG) { return "TRANSLATE(" + key + ") (param={0}}"; } else { try { ...
java
public String getBugCategoryDescription(String category) { BugCategory bc = DetectorFactoryCollection.instance().getBugCategory(category); return (bc != null ? bc.getShortDescription() : category); }
java
JPanel createSourceCodePanel() { Font sourceFont = new Font("Monospaced", Font.PLAIN, (int) Driver.getFontSize()); mainFrame.getSourceCodeTextPane().setFont(sourceFont); mainFrame.getSourceCodeTextPane().setEditable(false); mainFrame.getSourceCodeTextPane().getCaret().setSelectionVisible...
java
public void scrollLineToVisible(int line, int margin) { int maxMargin = (parentHeight() - 20) / 2; if (margin > maxMargin) { margin = Math.max(0, maxMargin); } scrollLineToVisibleImpl(line, margin); }
java
public void scrollLinesToVisible(int startLine, int endLine, Collection<Integer> otherLines) { int startY, endY; try { startY = lineToY(startLine); } catch (BadLocationException ble) { if (MainFrame.GUI2_DEBUG) { ble.printStackTrace(); } ...
java
private void examineBasicBlocks() throws DataflowAnalysisException, CFGBuilderException { // Look for null check blocks where the reference being checked // is definitely null, or null on some path Iterator<BasicBlock> bbIter = invDataflow.getCFG().blockIterator(); while (bbIter.hasNext(...
java
private void examineNullValues() throws CFGBuilderException, DataflowAnalysisException { Set<LocationWhereValueBecomesNull> locationWhereValueBecomesNullSet = invDataflow.getAnalysis() .getLocationWhereValueBecomesNullSet(); if (DEBUG_DEREFS) { System.out.println("-----------...
java
private void noteUnconditionallyDereferencedNullValue(Location thisLocation, Map<ValueNumber, SortedSet<Location>> bugLocations, Map<ValueNumber, NullValueUnconditionalDeref> nullValueGuaranteedDerefMap, UnconditionalValueDerefSet derefSet, IsNullValue isNullValue, ValueNumber valueN...
java
private void examineRedundantBranches() { for (RedundantBranch redundantBranch : redundantBranchList) { if (DEBUG) { System.out.println("Redundant branch: " + redundantBranch); } int lineNumber = redundantBranch.lineNumber; // The source to byteco...
java
private void analyzeIfNullBranch(BasicBlock basicBlock, InstructionHandle lastHandle) throws DataflowAnalysisException { Location location = new Location(lastHandle, basicBlock); IsNullValueFrame frame = invDataflow.getFactAtLocation(location); if (!frame.isValid()) { // This is p...
java
public @Nonnull BugPattern getBugPattern() { BugPattern result = DetectorFactoryCollection.instance().lookupBugPattern(getType()); if (result != null) { return result; } AnalysisContext.logError("Unable to find description of bug pattern " + getType()); result = Detec...
java
@CheckForNull private <T extends BugAnnotation> T findPrimaryAnnotationOfType(Class<T> cls) { T firstMatch = null; for (Iterator<BugAnnotation> i = annotationIterator(); i.hasNext();) { BugAnnotation annotation = i.next(); if (cls.isAssignableFrom(annotation.getClass())) { ...
java
public @CheckForNull <A extends BugAnnotation> A getAnnotationWithRole(Class<A> c, String role) { for(BugAnnotation a : annotationList) { if (c.isInstance(a) && Objects.equals(role, a.getDescription())) { return c.cast(a); } } return null; }
java
public String getProperty(String name) { BugProperty prop = lookupProperty(name); return prop != null ? prop.getValue() : null; }
java
public String getProperty(String name, String defaultValue) { String value = getProperty(name); return value != null ? value : defaultValue; }
java
@Nonnull public BugInstance setProperty(String name, String value) { BugProperty prop = lookupProperty(name); if (prop != null) { prop.setValue(value); } else { prop = new BugProperty(name, value); addProperty(prop); } return this; }
java
public BugProperty lookupProperty(String name) { BugProperty prop = propertyListHead; while (prop != null) { if (prop.getName().equals(name)) { break; } prop = prop.getNext(); } return prop; }
java
public boolean deleteProperty(String name) { BugProperty prev = null; BugProperty prop = propertyListHead; while (prop != null) { if (prop.getName().equals(name)) { break; } prev = prop; prop = prop.getNext(); } if...
java
@Nonnull public BugInstance addAnnotations(Collection<? extends BugAnnotation> annotationCollection) { for (BugAnnotation annotation : annotationCollection) { add(annotation); } return this; }
java
@Nonnull public BugInstance addClassAndMethod(PreorderVisitor visitor) { addClass(visitor); XMethod m = visitor.getXMethod(); addMethod(visitor); if (!MemberUtils.isUserGenerated(m)) { foundInAutogeneratedMethod(); } return this; }
java
@Nonnull public BugInstance addClassAndMethod(JavaClass javaClass, Method method) { addClass(javaClass.getClassName()); addMethod(javaClass, method); if (!MemberUtils.isUserGenerated(method)) { foundInAutogeneratedMethod(); } return this; }
java
@Nonnull public BugInstance addClass(ClassNode classNode) { String dottedClassName = ClassName.toDottedClassName(classNode.name); ClassAnnotation classAnnotation = new ClassAnnotation(dottedClassName); add(classAnnotation); return this; }
java
@Nonnull public BugInstance addClass(PreorderVisitor visitor) { String className = visitor.getDottedClassName(); addClass(className); return this; }
java
@Nonnull public BugInstance addSuperclass(PreorderVisitor visitor) { String className = ClassName.toDottedClassName(visitor.getSuperclassName()); addClass(className); return this; }
java
@Nonnull public BugInstance addType(String typeDescriptor) { TypeAnnotation typeAnnotation = new TypeAnnotation(typeDescriptor); add(typeAnnotation); return this; }
java
@Nonnull public BugInstance addField(String className, String fieldName, String fieldSig, boolean isStatic) { addField(new FieldAnnotation(className, fieldName, fieldSig, isStatic)); return this; }
java
@Nonnull public BugInstance addField(FieldVariable field) { return addField(field.getClassName(), field.getFieldName(), field.getFieldSig(), field.isStatic()); }
java
@Nonnull public BugInstance addField(FieldDescriptor fieldDescriptor) { FieldAnnotation fieldAnnotation = FieldAnnotation.fromFieldDescriptor(fieldDescriptor); add(fieldAnnotation); return this; }
java
@Nonnull public BugInstance addVisitedField(PreorderVisitor visitor) { FieldAnnotation f = FieldAnnotation.fromVisitedField(visitor); addField(f); return this; }
java
@Nonnull public BugInstance addOptionalLocalVariable(DismantleBytecode dbc, OpcodeStack.Item item) { int register = item.getRegisterNumber(); if (register >= 0) { this.add(LocalVariableAnnotation.getLocalVariableAnnotation(dbc.getMethod(), register, dbc.getPC() - 1, dbc.getPC())); ...
java
@Nonnull public BugInstance addMethod(PreorderVisitor visitor) { MethodAnnotation methodAnnotation = MethodAnnotation.fromVisitedMethod(visitor); addMethod(methodAnnotation); addSourceLinesForMethod(methodAnnotation, SourceLineAnnotation.fromVisitedMethod(visitor)); return this; ...
java
@Nonnull public BugInstance addCalledMethod(DismantleBytecode visitor) { return addMethod(MethodAnnotation.fromCalledMethod(visitor)).describe(MethodAnnotation.METHOD_CALLED); }
java
@Nonnull public BugInstance addCalledMethod(String className, String methodName, String methodSig, boolean isStatic) { return addMethod(MethodAnnotation.fromCalledMethod(className, methodName, methodSig, isStatic)).describe( MethodAnnotation.METHOD_CALLED); }
java
@Nonnull public BugInstance addParameterAnnotation(int index, String role) { return addInt(index + 1).describe(role); }
java
@Nonnull public BugInstance addString(char c) { add(StringAnnotation.fromRawString(Character.toString(c))); return this; }
java
@Nonnull public BugInstance addSourceLine(ClassContext classContext, MethodGen methodGen, String sourceFile, InstructionHandle start, InstructionHandle end) { // Make sure start and end are really in the right order. if (start.getPosition() > end.getPosition()) { InstructionH...
java
@Nonnull public BugInstance addUnknownSourceLine(String className, String sourceFile) { SourceLineAnnotation sourceLineAnnotation = SourceLineAnnotation.createUnknown(className, sourceFile); if (sourceLineAnnotation != null) { add(sourceLineAnnotation); } return this; ...
java
@Nonnull public BugInstance describe(String description) { annotationList.get(annotationList.size() - 1).setDescription(description); return this; }
java
public ExceptionSet getEdgeExceptionSet(Edge edge) { CachedExceptionSet cachedExceptionSet = thrownExceptionSetMap.get(edge.getSource()); return cachedExceptionSet.getEdgeExceptionSet(edge); }
java
private CachedExceptionSet getCachedExceptionSet(BasicBlock basicBlock) { CachedExceptionSet cachedExceptionSet = thrownExceptionSetMap.get(basicBlock); if (cachedExceptionSet == null) { // When creating the cached exception type set for the first time: // - the block result is s...
java
private CachedExceptionSet computeBlockExceptionSet(BasicBlock basicBlock, TypeFrame result) throws DataflowAnalysisException { ExceptionSet exceptionSet = computeThrownExceptionTypes(basicBlock); TypeFrame copyOfResult = createFact(); copy(result, copyOfResult); CachedExceptionSet c...
java
private ExceptionSet computeEdgeExceptionSet(Edge edge, ExceptionSet thrownExceptionSet) { if (thrownExceptionSet.isEmpty()) { return thrownExceptionSet; } ExceptionSet result = exceptionSetFactory.createExceptionSet(); if (edge.getType() == UNHANDLED_EXCEPTION_EDGE) { ...
java
private ExceptionSet computeThrownExceptionTypes(BasicBlock basicBlock) throws DataflowAnalysisException { ExceptionSet exceptionTypeSet = exceptionSetFactory.createExceptionSet(); InstructionHandle pei = basicBlock.getExceptionThrower(); Instruction ins = pei.getInstruction(); // ...
java
@CheckForNull public static JavaClass getOuterClass(JavaClass obj) throws ClassNotFoundException { for (Attribute a : obj.getAttributes()) { if (a instanceof InnerClasses) { for (InnerClass ic : ((InnerClasses) a).getInnerClasses()) { if (obj.getClassNameIndex...
java
public void addVerticesToSet(Set<VertexType> set) { // Add the vertex for this object set.add(this.m_vertex); // Add vertices for all children Iterator<SearchTree<VertexType>> i = childIterator(); while (i.hasNext()) { SearchTree<VertexType> child = i.next(); ...
java
private void checkQualifier(XMethod xmethod, CFG cfg, TypeQualifierValue<?> typeQualifierValue, ForwardTypeQualifierDataflowFactory forwardDataflowFactory, BackwardTypeQualifierDataflowFactory backwardDataflowFactory, ValueNumberDataflow vnaDataflow) throws CheckedAnalysisExc...
java
public void setMethodHash(XMethod method, byte[] methodHash) { methodHashMap.put(method, new MethodHash(method.getName(), method.getSignature(), method.isStatic(), methodHash)); }
java
public void setClassHash(byte[] classHash) { this.classHash = new byte[classHash.length]; System.arraycopy(classHash, 0, this.classHash, 0, classHash.length); }
java
public ClassHash computeHash(JavaClass javaClass) { this.className = javaClass.getClassName(); Method[] methodList = new Method[javaClass.getMethods().length]; // Sort methods System.arraycopy(javaClass.getMethods(), 0, methodList, 0, javaClass.getMethods().length); Arrays.sort...
java
public static String hashToString(byte[] hash) { StringBuilder buf = new StringBuilder(); for (byte b : hash) { buf.append(HEX_CHARS[(b >> 4) & 0xF]); buf.append(HEX_CHARS[b & 0xF]); } return buf.toString(); }
java
public static byte[] stringToHash(String s) { if (s.length() % 2 != 0) { throw new IllegalArgumentException("Invalid hash string: " + s); } byte[] hash = new byte[s.length() / 2]; for (int i = 0; i < s.length(); i += 2) { byte b = (byte) ((hexDigitValue(s.charAt(i...
java
public static Variable lookup(String varName, BindingSet bindingSet) { if (bindingSet == null) { return null; } Binding binding = bindingSet.lookup(varName); return (binding != null) ? binding.getVariable() : null; }
java
public WarningPropertySet<T> addProperty(T prop) { map.put(prop, Boolean.TRUE); return this; }
java
public WarningPropertySet<T> setProperty(T prop, String value) { map.put(prop, value); return this; }
java
public boolean checkProperty(T prop, Object value) { Object attribute = getProperty(prop); return (attribute != null && attribute.equals(value)); }
java
public int computePriority(int basePriority) { boolean relaxedReporting = FindBugsAnalysisFeatures.isRelaxedMode(); boolean atLeastMedium = false; boolean falsePositive = false; boolean atMostLow = false; boolean atMostMedium = false; boolean peggedHigh = false; ...
java
public void decorateBugInstance(BugInstance bugInstance) { int priority = computePriority(bugInstance.getPriority()); bugInstance.setPriority(priority); for (Map.Entry<T, Object> entry : map.entrySet()) { WarningProperty prop = entry.getKey(); Object attribute = entry.get...
java
public ValueNumber getEntryValueForParameter(int param) { SignatureParser sigParser = new SignatureParser(methodGen.getSignature()); int p = 0; int slotOffset = methodGen.isStatic() ? 0 : 1; for ( String paramSig : sigParser.parameterSignatures()) { if (p == param) { ...
java
public static void writeCollection(XMLOutput xmlOutput, Collection<? extends XMLWriteable> collection) throws IOException { for (XMLWriteable obj : collection) { obj.writeXML(xmlOutput); } }
java
@Override public void addParameterAnnotation(int param, AnnotationValue annotationValue) { HashMap<Integer, Map<ClassDescriptor, AnnotationValue>> updatedAnnotations = new HashMap<>( methodParameterAnnotations); Map<ClassDescriptor, AnnotationValue> paramMap = updatedAnnotations.get(...
java
String getResourceName() { if (!resourceNameKnown) { // The resource name of a classfile can only be determined by // reading // the file and parsing the constant pool. // If we can't do this for some reason, then we just // make the resource name equa...
java
public InputStream getInputStreamFromOffset(int offset) throws IOException { loadFileData(); return new ByteArrayInputStream(data, offset, data.length - offset); }
java
public void addLineOffset(int offset) { if (numLines >= lineNumberMap.length) { // Grow the line number map. int capacity = lineNumberMap.length * 2; int[] newLineNumberMap = new int[capacity]; System.arraycopy(lineNumberMap, 0, newLineNumberMap, 0, lineNumberMap....
java
public int getLineOffset(int line) { try { loadFileData(); } catch (IOException e) { System.err.println("SourceFile.getLineOffset: " + e.getMessage()); return -1; } if (line < 0 || line >= numLines) { return -1; } return lin...
java
public void findStronglyConnectedComponents(GraphType g, GraphToolkit<GraphType, EdgeType, VertexType> toolkit) { // Perform the initial depth first search DepthFirstSearch<GraphType, EdgeType, VertexType> initialDFS = new DepthFirstSearch<>(g); if (m_vertexChooser != null) { initia...
java
public Collection<String> split() { String s = ident; Set<String> result = new HashSet<>(); while (s.length() > 0) { StringBuilder buf = new StringBuilder(); char first = s.charAt(0); buf.append(first); int i = 1; if (s.length() > 1)...
java
private static void collectAllAnonymous(List<IType> list, IParent parent, boolean allowNested) throws JavaModelException { IJavaElement[] children = parent.getChildren(); for (int i = 0; i < children.length; i++) { IJavaElement childElem = children[i]; if (isAnonymousType(childEl...
java
private static void sortAnonymous(List<IType> anonymous, IType anonType) { SourceOffsetComparator sourceComparator = new SourceOffsetComparator(); final AnonymClassComparator classComparator = new AnonymClassComparator(anonType, sourceComparator); Collections.sort(anonymous, classComparator); ...
java
public static void addFindBugsNature(IProject project, IProgressMonitor monitor) throws CoreException { if (hasFindBugsNature(project)) { return; } IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); for (int ...
java
public static boolean hasFindBugsNature(IProject project) { try { return ProjectUtilities.isJavaProject(project) && project.hasNature(FindbugsPlugin.NATURE_ID); } catch (CoreException e) { FindbugsPlugin.getDefault().logException(e, "Error while testing SpotBugs nature for projec...
java
public static void removeFindBugsNature(IProject project, IProgressMonitor monitor) throws CoreException { if (!hasFindBugsNature(project)) { return; } IProjectDescription description = project.getDescription(); String[] prevNatures = description.getNatureIds(); Array...
java
public void execute() throws CFGBuilderException { JavaClass jclass = classContext.getJavaClass(); Method[] methods = jclass.getMethods(); LOG.debug("Class has {} methods", methods.length); // Add call graph nodes for all methods for (Method method : methods) { call...
java
public Iterator<CallSite> callSiteIterator() { return new Iterator<CallSite>() { private final Iterator<CallGraphEdge> iter = callGraph.edgeIterator(); @Override public boolean hasNext() { return iter.hasNext(); } @Override ...
java