Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * fb-contrib - Auxiliary detectors for Java programs
   * Copyright (C) 2005-2013 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
  * 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.Set;
 import  org.apache.bcel.classfile.Constant;
 import  org.apache.bcel.classfile.ConstantClass;
 import  org.apache.bcel.classfile.ConstantPool;
 import  org.apache.bcel.classfile.JavaClass;
 import  edu.umd.cs.findbugs.BugInstance;
 import  edu.umd.cs.findbugs.BugReporter;
 import  edu.umd.cs.findbugs.Detector;

looks for classes that use objects from packages. As these are internal to sun and subject to change, this should not be done.
 public class IncorrectInternalClassUse implements Detector
     private final BugReporter bugReporter;
     private static final Set<StringinternalPackages = new HashSet<String>();
     private static final Set<StringexternalPackages = new HashSet<String>();
     static {

constructs a IICU detector given the reporter to report bugs on

bugReporter the sync of bug reports
     public IncorrectInternalClassUse(BugReporter bugReporter) {
         this. = bugReporter;

implements the visitor to look for classes that reference, or classes by looking for class constants in the constant pool

context the context object of the currently parsed class
     public void visitClassContext(ClassContext context) {
         JavaClass cls = context.getJavaClass();
         if (!isInternal(cls.getClassName())) {
             ConstantPool pool = cls.getConstantPool();
             int numItems = pool.getLength();
             for (int i = 0; i < numItemsi++) {
                 Constant c = pool.getConstant(i);
                 if (c instanceof ConstantClass) {
                     String clsName = ((ConstantClass) c).getBytes(pool);
                     if (isInternal(clsName)) {
                         .reportBug(new BugInstance(this"IICU_INCORRECT_INTERNAL_CLASS_USE", NORMAL_PRIORITY)

implementation stub for Detector interface
     public void report() {

determines if the class in question is an internal class by looking at package prefixes

clsName the name of the class to check
whether the class is internal
     private boolean isInternal(String clsName) {
         boolean internal = false;
        for (String internalPackage : ) {
            if (clsName.startsWith(internalPackage)) {
                internal = true;
        if (internal) {
            for (String externalPackage : ) {
                if (clsName.startsWith(externalPackage)) {
                    internal = false;
        return internal;
New to GrepCode? Check out our FAQ X