You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/07/04 00:36:39 UTC

svn commit: r553008 - in /db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile: ClassHolder.java ClassInvestigator.java

Author: djd
Date: Tue Jul  3 15:36:38 2007
New Revision: 553008

URL: http://svn.apache.org/viewvc?view=rev&rev=553008
Log:
Allow the class holder code to support a different major/minor version if the class is read in.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassHolder.java
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassInvestigator.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassHolder.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassHolder.java?view=diff&rev=553008&r1=553007&r2=553008
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassHolder.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassHolder.java Tue Jul  3 15:36:38 2007
@@ -57,7 +57,26 @@
 	/*
 	** Fields
 	*/
-
+    
+    /**
+     * Minor class format number defaults to 
+     * VMDescriptor.JAVA_CLASS_FORMAT_MINOR_VERSION
+     * which currently corresponds to a really old (JDK 1.0.2) setting.
+     * The default major and minor value is used by the generated code for Derby's
+     * SQL statements. Currently there is no need to bump the version
+     * number as the generated code does not take advantage of any of the
+     * new elements in the class file format. If such a need exists then
+     * this can be bumped. One issue is that the change in format numbers
+     * is not well documented.
+     */
+    protected int minor_version = VMDescriptor.JAVA_CLASS_FORMAT_MINOR_VERSION;
+
+    /**
+     * Minor class format number defaults to 
+     * VMDescriptor.JAVA_CLASS_FORMAT_MAJOR_VERSION
+     */
+    protected int major_version = VMDescriptor.JAVA_CLASS_FORMAT_MAJOR_VERSION;
+    
 	protected int access_flags;
 	protected int this_class;
 	protected int super_class;
@@ -118,8 +137,8 @@
 
 		/* Write out the header */
 		out.putU4(VMDescriptor.JAVA_CLASS_FORMAT_MAGIC);
-		out.putU2(VMDescriptor.JAVA_CLASS_FORMAT_MINOR_VERSION);
-		out.putU2(VMDescriptor.JAVA_CLASS_FORMAT_MAJOR_VERSION);
+		out.putU2(minor_version);
+		out.putU2(major_version);
 
 		// special case checking that the number of constant
 		// pool entries does not exceed the limit of 65535

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassInvestigator.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassInvestigator.java?view=diff&rev=553008&r1=553007&r2=553008
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassInvestigator.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/classfile/ClassInvestigator.java Tue Jul  3 15:36:38 2007
@@ -49,12 +49,21 @@
 		ClassInput classInput = new ClassInput(is);
 
 		// Check the header
-		checkHeader(classInput);
+        int magic = classInput.getU4();
+        int minor_version = classInput.getU2();
+        int major_version = classInput.getU2();
+
+        if (magic != VMDescriptor.JAVA_CLASS_FORMAT_MAGIC)
+               throw new ClassFormatError();
 
 		//	Read in the Constant Pool
 		int constantPoolCount = classInput.getU2();
 
 		ClassInvestigator ci = new ClassInvestigator(constantPoolCount);
+        
+        ci.minor_version = minor_version;
+        ci.major_version = major_version;      
+        
 		// Yes, index starts at 1, The '0'th constant pool entry
 		// is reserved for the JVM and is not present in the class file.
 		for (int i = 1; i < constantPoolCount; ) {
@@ -451,25 +460,13 @@
 		CONSTANT_Utf8_info newCpe = new CONSTANT_Utf8_info(newName);
 
 		cptHashTable.remove(cpe.getKey());
-		cptHashTable.put(cpe.getKey(), cpe);
+		cptHashTable.put(newCpe.getKey(), newCpe);
 
 		newCpe.index = index;
 
 		cptEntries.setElementAt(newCpe, index);
 	}
 
-	/*
-	**
-	*/
-	static private void checkHeader(ClassInput in) throws IOException {
-		int magic = in.getU4();
-		int minor_version = in.getU2();
-		int major_version = in.getU2();
-
-
-		if (magic != VMDescriptor.JAVA_CLASS_FORMAT_MAGIC)
-			   throw new ClassFormatError();
-   	}
 	private static ConstantPoolEntry getConstant(ClassInput in)
 		throws IOException {