You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2015/08/21 12:08:28 UTC

svn commit: r1696923 - in /commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6: Constants.java classfile/ClassParser.java classfile/JavaClass.java verifier/statics/Pass1Verifier.java

Author: sebb
Date: Fri Aug 21 10:08:27 2015
New Revision: 1696923

URL: http://svn.apache.org/r1696923
Log:
Constant for class file magic number

Modified:
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ClassParser.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/JavaClass.java
    commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass1Verifier.java

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java?rev=1696923&r1=1696922&r2=1696923&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/Constants.java Fri Aug 21 10:08:27 2015
@@ -24,6 +24,14 @@ package org.apache.commons.bcel6;
  */
 public final class Constants {
 
+  /**
+   * Java class file format Magic number (0xCAFEBABE)
+   *
+   * @see <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.1-200-A">
+   * The ClassFile Structure in The Java Virtual Machine Specification</a>
+   */
+  public static final int JVM_CLASSFILE_MAGIC = 0xCAFEBABE;
+
   /** Major version number of class files for Java 1.1.
    *  @see #MINOR_1_1
    *  */

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ClassParser.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ClassParser.java?rev=1696923&r1=1696922&r2=1696923&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ClassParser.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/ClassParser.java Fri Aug 21 10:08:27 2015
@@ -258,8 +258,7 @@ public final class ClassParser {
      * @throws  ClassFormatException
      */
     private void readID() throws IOException, ClassFormatException {
-        int magic = 0xCAFEBABE;
-        if (dataInputStream.readInt() != magic) {
+        if (dataInputStream.readInt() != Constants.JVM_CLASSFILE_MAGIC) {
             throw new ClassFormatException(file_name + " is not a Java .class file");
         }
     }

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/JavaClass.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/JavaClass.java?rev=1696923&r1=1696922&r2=1696923&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/JavaClass.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/classfile/JavaClass.java Fri Aug 21 10:08:27 2015
@@ -297,7 +297,7 @@ public class JavaClass extends AccessFla
      * @exception IOException
      */
     public void dump( DataOutputStream file ) throws IOException {
-        file.writeInt(0xcafebabe);
+        file.writeInt(Constants.JVM_CLASSFILE_MAGIC);
         file.writeShort(minor);
         file.writeShort(major);
         constant_pool.dump(file);

Modified: commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass1Verifier.java
URL: http://svn.apache.org/viewvc/commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass1Verifier.java?rev=1696923&r1=1696922&r2=1696923&view=diff
==============================================================================
--- commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass1Verifier.java (original)
+++ commons/proper/bcel/trunk/src/main/java/org/apache/commons/bcel6/verifier/statics/Pass1Verifier.java Fri Aug 21 10:08:27 2015
@@ -82,7 +82,7 @@ public final class Pass1Verifier extends
      * The answer is that only pass one is performed on a class file as
      * long as its resolution is not requested; whereas pass two and
      * pass three are performed during the resolution process.
-     * Only four constraints to be checked are explicitely stated by
+     * Only four constraints to be checked are explicitly stated by
      * The Java Virtual Machine Specification, 2nd edition:
      * <UL>
      *  <LI>The first four bytes must contain the right magic number (0xCAFEBABE).
@@ -141,6 +141,7 @@ public final class Pass1Verifier extends
      * (otherwise you would not be able to load it into BCEL).</P>
      *
      * @see org.apache.commons.bcel6.Repository
+     * @see org.apache.commons.bcel6.Constants#JVM_CLASSFILE_MAGIC
      */
     @Override
     public VerificationResult do_verify(){