db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Andrew McIntyre" <mcintyr...@gmail.com>
Subject ij gets UnsupportedClassVersionError with JDK 1.3.1 (DERBY-1609)
Date Tue, 01 Aug 2006 01:01:12 GMT
A recent change to ij.java added the following line:

+		  ijE = new org.apache.derby.impl.tools.ij.Main14(false);

Apparently the default classloader, when it sees that this class may
be instantiated, will attempt to load this class. On JDK 1.3.1, this
leads to an UnsupportedClassVersionError being thrown, since Main14 is
compiled with "-target 1.4". The solution is probably to load the
class via reflection. At the end of this mail is a proposed solution,
but I'm sure it could be improved. I simply catch and report any of
the exceptions that are thrown by the reflection methods. We're
unlikely to hit any of them, and throwing them seemed like quite a
burden for a public API, but maybe there's a better way to handle all
these. I also haven't tried this with the security manager yet.

Any comments greatly appreciated. If anyone feels this requires a JIRA
to fix, let me know, otherwise, it might be considered a part of
DERBY-1609.

Thanks,
andrew


Index: java/tools/org/apache/derby/tools/ij.java
===================================================================
--- java/tools/org/apache/derby/tools/ij.java	(revision 427381)
+++ java/tools/org/apache/derby/tools/ij.java	(working copy)
@@ -32,6 +32,10 @@
 import java.io.InputStream;
 import java.io.PrintStream;
 import java.io.UnsupportedEncodingException;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
 import java.sql.Connection;
 import java.util.Properties;

@@ -98,14 +102,33 @@
 		          LocalizedResource.getInstance().
                     getNewEncodedOutput(sqlOut, outputEncoding);

-	  Main ijE;
+	  Main ijE = null;
 	  if (JVMInfo.JDK_ID == JVMInfo.J2SE_13)
 	  {
 		  ijE = new Main(false);
 	  }
 	  else
 	  {
-		  ijE = new org.apache.derby.impl.tools.ij.Main14(false);
+                  /* instantiate Main14 via reflection. In JDK 1.3.1, the
+                   * VM will attempt to load the class when it sees the
+                   * invokespecial instruction with the constuctor for Main14,
+                   * which would cause an UnsupportedClassVersion to be thrown.
+                   */
+                  try {
+                      Class ijC =
Class.forName("org.apache.derby.impl.tools.ij.Main14");
+                      Constructor ijCconstruct =
ijC.getConstructor(new Class [] { boolean.class });
+		      ijE = (Main)ijCconstruct.newInstance( new Object[] { new
Boolean(false) });
+                  } catch (ClassNotFoundException cnfe) {
+                      cnfe.printStackTrace();
+                  } catch (NoSuchMethodException nsme) {
+                      nsme.printStackTrace();
+                  } catch (InstantiationException ie) {
+                      ie.printStackTrace();
+                  } catch (IllegalAccessException iae) {
+                      iae.printStackTrace();
+                  } catch (InvocationTargetException ite) {
+                      ite.printStackTrace();
+                  }
 	  }	
 	
 	  LocalizedInput li = LocalizedResource.getInstance().

Mime
View raw message