Uploaded image for project: 'Commons BCEL'
  1. Commons BCEL
  2. BCEL-100

ClassParser throws unintelligible Exception

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Blocker
    • Resolution: Fixed
    • None
    • 6.0
    • Main
    • None

    Description

      o.a.b.classfile.ClassParser throws two exceptions. One has the file_name
      variable included but the one that only comes up when you have a corrupted class
      file does not. When you have thousands and thousands of classes (counting all
      the classes in dependent jars) in a large project, this can make it very
      difficult to find the problem!

      One could in theory argue that the application using BCEL should report this,
      but the canonical example of a file-related problem is FileNotFoundException
      which does include the filename, for the same reason as I suggest the exception
      thrown by ClassParser does. E.g., create new FileReader("/nosuchfile") and you get:

      Exception in thread "main" java.io.FileNotFoundException: /nosuchfile (No such
      file or directory)

      A simple SVN patch against r516101 follows (bigger than it needs to be due to
      Eclipse's auto-remove-excess-whitespace mode):

      Index:
      /home/ian/workspace/bcel/src/main/java/org/apache/bcel/classfile/ClassParser.java
      ===================================================================

      /home/ian/workspace/bcel/src/main/java/org/apache/bcel/classfile/ClassParser.java
      (revision 516101)
      +++
      /home/ian/workspace/bcel/src/main/java/org/apache/bcel/classfile/ClassParser.java
      (working copy)
      @@ -38,7 +38,7 @@

      • further details about the structure of a bytecode file.
        *
      • @version $Id$
      • * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
        + * @author <A HREF="mailto:m.dahm@gmx.de">M. Dahm</A>
        */
        public final class ClassParser { @@ -206,7 +206,8 @@ }

        if (((access_flags & Constants.ACC_ABSTRACT) != 0)
        && ((access_flags & Constants.ACC_FINAL) != 0))

        { - throw new ClassFormatException("Class can't be both final and abstract"); + throw new ClassFormatException( + "Class " + file_name + " can't be both final and abstract"); }

        class_name_index = file.readUnsignedShort();
        superclass_name_index = file.readUnsignedShort();

      Attachments

        Activity

          People

            issues@commons.apache.org Apache Commons Developers
            ian988@darwinsys.com Ian Darwin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: