Hi all,

I've managed to get JBoss 3.2.2 to load & run the management console on kaffe from CVS + a few patches that I haven't committed yet. The patches are
a) a bugfix for Socket.close() being called twice
b) a rewrite of kaffe's RessourceBundle, since ours & classpath's was broken
c) a 'fix' for ZipFile.close releasing zip ptr.


The patches ara attached for your testing & bugfixing pleasure. They apply vs the current CVS.

The usual rules apply: set JAVA_HOME to where you've installed kaffe, set JAVA_OPTS to use kjc as the compiler, lots of memory and a big stack, as in
export JAVA_OPTS="-mx256M -ss256K -Dbuild.compiler=kjc".


Will this make it into 1.1.3, you may ask. Well, a) is a bugfix and will go in for sure, b) depends on mauve test results and if Jim OKs it for 1.1.3 and c) is somewhat of a hack, necessary for JBoss but I don't understand why it breaks otherwise.

There is also a stack of rather weird exceptions being thrown ocassionally, that need some fixing. I doubt I'll have the time to clear everything up till Sunday evening, but I'll try to fix as much as I can.

Thew obligatory screenhot is at http://www.kaffe.org/~robilad/jboss-3.2.2-screenshot.png

thanks to everyone who made this possible. keep up the great work!

cheers,
dalibor topic
Index: libraries/javalib//java/net/Socket.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/net/Socket.java,v
retrieving revision 1.28
diff -u -r1.28 Socket.java
--- libraries/javalib//java/net/Socket.java     3 Dec 2003 23:18:04 -0000       1.28
+++ libraries/javalib//java/net/Socket.java     6 Dec 2003 09:37:34 -0000
@@ -1003,7 +1003,7 @@
   public synchronized void close ()  throws IOException
   {
     if (isClosed())
-      throw new SocketException("socket is closed");
+      return;
     
     getImpl().close();
     impl = null;
Index: libraries/javalib//java/util/ResourceBundle.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/ResourceBundle.java,v
retrieving revision 1.16
diff -u -r1.16 ResourceBundle.java
--- libraries/javalib//java/util/ResourceBundle.java    28 Jun 2003 18:06:41 -0000     
 1.16
+++ libraries/javalib//java/util/ResourceBundle.java    6 Dec 2003 09:37:34 -0000
@@ -39,75 +39,146 @@
 public static ResourceBundle getBundle(String baseName, Locale locale,
                ClassLoader loader) throws MissingResourceException {
        
-       ResourceBundle defaultBundle = getSpecificBundle (baseName, loader);
-       if (defaultBundle != null) {
-               defaultBundle.parent = null;
-               defaultBundle.locale = new Locale ("");
-       }
+  List names = generateCandidateBundleNames(baseName, locale);
+  Iterator iter = names.iterator();
 
-       ResourceBundle ret = getBundleWithLocale(baseName, defaultBundle, locale, 
loader);
+  while (iter.hasNext()) {
+    String name = (String) iter.next();
 
-       /* It would appear that if we fail to load a resource bundle
-        * for a given locale, we just load the default one instead.
-        */
-       if (ret==defaultBundle && locale != Locale.getDefault()) {
-               ret = getBundleWithLocale(baseName, defaultBundle,
-                   Locale.getDefault(), loader);
-       }
+    ResourceBundle bundle = getFromCache(name, loader);
+    if (bundle == null) {
+      bundle = instantiate(name, loader);
+    }
+
+    if (bundle != null) {
+      putInCache(name, loader, bundle);
+      instantiateParentChain(bundle, name, loader);
+      return bundle;
+    }
+  }
+
+  throw new MissingResourceException("BaseName: " + baseName + " Locale: " + locale + 
" ClassLoader : " + loader, "ResourceBundle", baseName);
+}
 
-       if (ret == null) {
-               throw new MissingResourceException("Can't find bundle for base name "
-                   + baseName + ",locale " + locale, "ResourceBundle", baseName);
-       }
 
-       return (ret);
+  private static ResourceBundle getFromCache(String name, ClassLoader loader) {
+    
+    return (ResourceBundle)cache.get (loader + name);
+  }
+
+  private static void putInCache(String name, ClassLoader loader, ResourceBundle 
bundle) {
+
+    cache.put (loader + name, bundle);
+  }
+
+  private static void instantiateParentChain(ResourceBundle bundle, String name, 
ClassLoader loader) {
+
+    int last_underscore = name.lastIndexOf('_');
+    if (last_underscore != -1) {
+      String parent_name = name.substring(0, last_underscore);
+      ResourceBundle parent = instantiate(parent_name, loader);
+      bundle.setParent(parent);
+      if (parent != null && parent.parent == null) {
+       instantiateParentChain(parent, parent_name, loader);
+      }
+    }
+  }
+  
+  private static ResourceBundle loadProperties(String name, ClassLoader loader) {
+    InputStream strm;
+    strm = loader.getResourceAsStream(name.replace('.', '/')
+                                     + ".properties");
+    if (strm != null) {
+      try {
+       return (new PropertyResourceBundle(strm));
+      }
+      catch (IOException e) {
+       e.printStackTrace();
+      }
+    }
+    
+    return null;
+  }
+  
+  private static ResourceBundle loadClass(String name, ClassLoader loader) {
+    try {
+      Class cls = Class.forName(name.replace('/', '.'), true, loader);
+      /* 
+       * Only call newInstance if the cast to resource bundle 
+       * will indeed succeed.
+       */
+      if (ResourceBundle.class.isAssignableFrom(cls)) {
+       return ((ResourceBundle)cls.newInstance());
+      }
+    }
+    catch (ClassNotFoundException e) {
+      // ignore
+    }
+    catch (LinkageError e) {
+      e.printStackTrace();
+    }
+    catch (IllegalAccessException e) {
+      e.printStackTrace();
+    }
+    catch (InstantiationException e) {
+      e.printStackTrace();
+    }
+
+    return null;
+  }
+
+private static ResourceBundle instantiate(String name, ClassLoader loader) {
+
+  ResourceBundle bundle = loadClass(name, loader);
+  if (bundle != null) {
+    return bundle;
+  }
+
+  bundle = loadProperties(name, loader);
+  return bundle;
 }
 
-private static final ResourceBundle getBundleWithLocale(String baseName, 
ResourceBundle bundle,
-               Locale locale, ClassLoader loader) {
-       ResourceBundle nbundle = null;
-
-       String lang = locale.getLanguage();
-       String cntry = locale.getCountry();
-       String var = locale.getVariant();
-
-       StringBuffer sb = new StringBuffer(60);
-       sb.append (baseName);
-
-       sb.append ('_');
-       if (lang.length()>0) {
-               sb.append (lang);
-               nbundle = getSpecificBundle(sb.toString(), loader);
-               if (nbundle != null) {
-                       nbundle.parent = bundle;
-                       nbundle.locale = new Locale (lang);
-                       bundle = nbundle;
-               }
-       }
+private static List generateCandidateBundleNames(String baseName, Locale locale) {
+  
+  String language1 = locale.getLanguage();
+  String country1 = locale.getCountry();
+  String variant1 = locale.getVariant();
+
+  Locale default_locale = Locale.getDefault();
+
+  String language2 = default_locale.getLanguage();
+  String country2 = default_locale.getCountry();
+  String variant2 = default_locale.getVariant();
+ 
+  List names = new ArrayList();
 
-       sb.append ('_');
-       if (cntry.length()>0) {
-               sb.append (cntry);      
-               nbundle = getSpecificBundle(sb.toString(), loader);
-               if (nbundle != null) {
-                       nbundle.parent = bundle;
-                       nbundle.locale = new Locale (lang, cntry);
-                       bundle = nbundle;
-               }
-       }
+  if (variant1.length() != 0) {
+    names.add(baseName + '_' + language1 + '_' + country1 + '_' + variant1);
+  }
 
-       if (var.length()>0) {
-               sb.append ('_');
-               sb.append (var);
-               nbundle = getSpecificBundle(sb.toString(), loader);
-               if (nbundle != null) {  
-                       nbundle.parent = bundle;
-                       nbundle.locale = new Locale (lang, cntry, var);
-                       bundle = nbundle;
-               }
-       }
-       
-       return (bundle);
+  if (country1.length() != 0) {
+    names.add(baseName + '_' + language1 + '_' + country1);
+  }
+
+  if (language1.length() != 0) {
+    names.add(baseName + '_' + language1);
+  }
+
+  if (variant2.length() != 0) {
+    names.add(baseName + '_' + language2 + '_' + country2 + '_' + variant2);
+  }
+
+  if (country2.length() != 0) {
+    names.add(baseName + '_' + language2 + '_' + country2);
+  }
+
+  if (language2.length() != 0) {
+    names.add(baseName + '_' + language2);
+  }
+
+  names.add(baseName);
+
+  return names;
 }
 
 public Locale getLocale () {
@@ -124,54 +195,13 @@
                }
        }
        catch (MissingResourceException e) {
+         e.printStackTrace();
        }
        if (parent == null) {
                throw new MissingResourceException("resource not found",
                    this.getClass().toString(), key);
        }
        return (parent.getObject(key));
-}
-
-private static final ResourceBundle getSpecificBundle(String baseName,
-               ClassLoader loader) {
-
-       ResourceBundle ret = (ResourceBundle)cache.get (loader + baseName);
-       if (ret != null) {
-               return ret;
-       }
- 
-       try {
-               Class cls = Class.forName(baseName, true, loader);
-               /* 
-                * Only call newInstance if the cast to resource bundle 
-                * will indeed succeed.
-                */
-               if (ResourceBundle.class.isAssignableFrom(cls)) {
-                       ret = ((ResourceBundle)cls.newInstance());
-               }
-       }
-       catch (Exception _) {
-       }
-
-       // Okay, failed to load bundle - attempt to load properties as bundle.
-       if (ret == null) {
-               InputStream strm;
-               strm = loader.getResourceAsStream(baseName.replace('.', '/')
-                       + ".properties");
-               if (strm != null) {
-                       try {
-                               ret = (new PropertyResourceBundle(strm));
-                       }
-                       catch (IOException _) {
-                       }
-               }
-       }
-
-       if (ret!=null) {
-               cache.put (baseName, ret);
-       }
-
-       return ret;
 }
 
 public final String getString(String key) throws MissingResourceException {
Index: libraries/javalib//java/util/zip/ZipFile.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/zip/ZipFile.java,v
retrieving revision 1.12
diff -u -r1.12 ZipFile.java
--- libraries/javalib//java/util/zip/ZipFile.java       27 Oct 2003 02:12:59 -0000     
 1.12
+++ libraries/javalib//java/util/zip/ZipFile.java       6 Dec 2003 09:37:34 -0000
@@ -59,10 +59,7 @@
 
 public void close() throws IOException
 {
-       if (zip != null) {
-               closeZipFile0(zip);
-               zip = null;
-       }
+  /* do nothing, or JBoss breaks for some weird reason */
 }
 
 public Enumeration entries()
@@ -71,9 +68,9 @@
        return (all.elements());
 }
 
-public ZipEntry getEntry(String zname)
+public ZipEntry getEntry(String zname) throws IllegalStateException
 {
-       return (getZipEntry0(zip, zname));
+  return (getZipEntry0(zip, zname));
 }
 
 public InputStream getInputStream(ZipEntry ze) throws IOException

Reply via email to