$OpenBSD: patch-jdk_src_share_classes_java_lang_ClassLoader_java,v 1.2 2009/01/04 23:25:16 kurt Exp $
--- jdk/src/share/classes/java/lang/ClassLoader.java.orig	Thu Jul 17 03:43:19 2008
+++ jdk/src/share/classes/java/lang/ClassLoader.java	Fri Aug  8 16:13:51 2008
@@ -27,6 +27,7 @@ package java.lang;
 import java.io.InputStream;
 import java.io.IOException;
 import java.io.File;
+import java.io.FilenameFilter;
 import java.lang.reflect.Constructor;
 import java.lang.reflect.InvocationTargetException;
 import java.net.MalformedURLException;
@@ -48,6 +49,7 @@ import java.util.Set;
 import java.util.Stack;
 import java.util.Map;
 import java.util.Vector;
+import java.util.Arrays;
 import sun.misc.ClassFileTransformer;
 import sun.misc.CompoundEnumeration;
 import sun.misc.Resource;
@@ -1706,18 +1708,42 @@ public abstract class ClassLoader {
     }
 
     private static boolean loadLibrary0(Class fromClass, final File file) {
-        boolean exists = AccessController.doPrivileged(
+	File libfile = (File) AccessController.doPrivileged(
             new PrivilegedAction<Object>() {
+		class LibraryFileFilter implements FilenameFilter {
+		    String lib_name;
+		    LibraryFileFilter(String lib_name) { this.lib_name = lib_name; }
+		    public boolean accept(File dir, String name) {
+			if (name.startsWith(lib_name)) {
+			    return name.substring(lib_name.length()).matches("\056[0-9]+\056[0-9]+$");
+			}
+			return false;
+		    }
+		}
+
                 public Object run() {
-                    return file.exists() ? Boolean.TRUE : null;
-                }})
-            != null;
-        if (!exists) {
+		    if (file.exists())
+			return file;
+		    // if file is unversioned, check for a versioned one in same dir
+		    if (file.getName().endsWith(".so")) {
+			File dir = file.getParentFile();
+			if (dir != null) {
+			    String liblist[] = dir.list(new LibraryFileFilter(file.getName()));
+			    if (liblist != null && liblist.length > 0) {
+				// return the highest versioned lib
+				Arrays.sort(liblist);
+				return new File(dir, liblist[liblist.length - 1]);
+			    }
+			}
+		    }
+		    return null;
+                }});
+	if (libfile == null) {
             return false;
         }
         String name;
         try {
-            name = file.getCanonicalPath();
+            name = libfile.getCanonicalPath();
         } catch (IOException e) {
             return false;
         }
