public void visitJavaClass()

in src/main/java/org/apache/bcel/verifier/statics/Pass2Verifier.java [682:730]


        public void visitJavaClass(final JavaClass obj) {
            final Attribute[] atts = obj.getAttributes();
            boolean foundSourceFile = false;
            boolean foundInnerClasses = false;

            // Is there an InnerClass referenced?
            // This is a costly check; existing verifiers don't do it!
            final boolean hasInnerClass = new InnerClassDetector(jc).innerClassReferenced();

            for (final Attribute att : atts) {
                if (!(att instanceof SourceFile) && !(att instanceof Deprecated) && !(att instanceof InnerClasses) && !(att instanceof Synthetic)) {
                    addMessage("Attribute '" + tostring(att) + "' as an attribute of the ClassFile structure '" + tostring(obj)
                        + "' is unknown and will therefore be ignored.");
                }

                if (att instanceof SourceFile) {
                    if (foundSourceFile) {
                        throw new ClassConstraintException(
                            "A ClassFile structure (like '" + tostring(obj) + "') may have no more than one SourceFile attribute."); // vmspec2 4.7.7
                    }
                    foundSourceFile = true;
                }

                if (att instanceof InnerClasses) {
                    if (!foundInnerClasses) {
                        foundInnerClasses = true;
                    } else if (hasInnerClass) {
                        throw new ClassConstraintException("A Classfile structure (like '" + tostring(obj) + "') must have exactly one InnerClasses attribute"
                            + " if at least one Inner Class is referenced (which is the case)." + " More than one InnerClasses attribute was found.");
                    }
                    if (!hasInnerClass) {
                        addMessage("No referenced Inner Class found, but InnerClasses attribute '" + tostring(att)
                            + "' found. Strongly suggest removal of that attribute.");
                    }
                }

            }
            if (hasInnerClass && !foundInnerClasses) {
                // throw new ClassConstraintException("A Classfile structure (like '"+tostring(obj)+
                // "') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case)."+
                // " No InnerClasses attribute was found.");
                // vmspec2, page 125 says it would be a constraint: but existing verifiers
                // don't check it and javac doesn't satisfy it when it comes to anonymous
                // inner classes
                addMessage("A Classfile structure (like '" + tostring(obj)
                    + "') must have exactly one InnerClasses attribute if at least one Inner Class is referenced (which is the case)."
                    + " No InnerClasses attribute was found.");
            }
        }