$OpenBSD: patch-j2se_src_share_classes_java_lang_ClassLoader_java,v 1.1 2005/02/04 17:06:45 kurt Exp $
--- j2se/src/share/classes/java/lang/ClassLoader.java.orig	Wed Sep 10 21:48:40 2003
+++ j2se/src/share/classes/java/lang/ClassLoader.java	Mon Jan  3 15:41:35 2005
@@ -9,6 +9,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;
@@ -29,6 +30,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;
@@ -1492,18 +1494,43 @@ public abstract class ClassLoader {
     }
 
     private static boolean loadLibrary0(Class fromClass, final File file) {
-	Boolean exists = (Boolean)
+	File libfile = (File)
 	    AccessController.doPrivileged(new PrivilegedAction() {
+		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 new Boolean(file.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 (!exists.booleanValue()) {
+	if (libfile == null) {
 	    return false;
 	}
         String name;
 	try {
-	    name = file.getCanonicalPath();
+	    name = libfile.getCanonicalPath();
 	} catch (IOException e) {
 	    return false;
 	}
