[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] Better reporting of JavaHL loading exceptions

From: Conor MacNeill <conor_at_cenqua.com>
Date: 2007-05-29 09:38:04 CEST

Hi,

This change retains the first thrown exception when attempting to load
the svnjavahl-1 native library rather than throwing the exception from
the last attempt. This is important when the user specifies the library
to load and it cannot be loaded. At present the error that finally gets
returned to the user is not the one related to the attempt to load their
library.

On my system for example, the change lets me see this error:

Could not load svn-javahl:
java.lang.UnsatisfiedLinkError-C:\Software\svn-dev\javahl\libsvnjavahl-1.dll:
Can't load IA 32-bit .dll on a AMD 64-bit platform

which before I could not. Here is my suggested log message:

[[[
Better error reporting when unable to load the Native JavaHL library

*
subversion/bindings/javahl/src/org/tigris/subversion/javahl/NativeResources.java
 (loadNativeLibrary): Use the earliest exception to report to the user
rather than the last
]]]

Let me know if I goofed.

Conor

Index: subversion/bindings/javahl/src/org/tigris/subversion/javahl/NativeResources.java
===================================================================
--- subversion/bindings/javahl/src/org/tigris/subversion/javahl/NativeResources.java (revision 25175)
+++ subversion/bindings/javahl/src/org/tigris/subversion/javahl/NativeResources.java (working copy)
@@ -47,6 +47,8 @@
      */
     public static synchronized void loadNativeLibrary()
     {
+ UnsatisfiedLinkError loadException = null;
+
         // If the user specified the fully qualified path to the
         // native library, try loading that first.
         try
@@ -62,7 +64,9 @@
         }
         catch (UnsatisfiedLinkError ex)
         {
- // ignore that error to try again
+ // Since the user specified this, it is the best error to return if
+ // no other method succeeds
+ loadException = ex;
         }
 
         // Try to load the library by its name. Failing that, try to
@@ -75,19 +79,47 @@
         }
         catch (UnsatisfiedLinkError ex)
         {
- try
+ if (loadException == null)
             {
- System.loadLibrary("libsvnjavahl-1");
- init();
- return;
+ loadException = ex;
             }
- catch (UnsatisfiedLinkError e)
+ }
+
+ try
+ {
+ System.loadLibrary("libsvnjavahl-1");
+ init();
+ return;
+ }
+ catch (UnsatisfiedLinkError ex)
+ {
+ if (loadException == null)
             {
- System.loadLibrary("svnjavahl");
- init();
- return;
+ loadException = ex;
             }
         }
+
+ try
+ {
+ System.loadLibrary("svnjavahl");
+ init();
+ return;
+ }
+ catch (UnsatisfiedLinkError ex)
+ {
+ if (loadException == null)
+ {
+ loadException = ex;
+ }
+ }
+
+ // rethrow
+ if (loadException == null)
+ {
+ // should never happen
+ throw new UnsatisfiedLinkError("Unable to load JavaHL native library");
+ }
+ throw loadException;
     }
 
     /**

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue May 29 09:38:43 2007

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.