You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by jc...@apache.org on 2005/05/04 15:19:08 UTC
cvs commit: jakarta-hivemind/framework/src/java/org/apache/hivemind/impl MessageFormatter.java
jcarman 2005/05/04 06:19:08
Modified: . status.xml
framework/src/java/org/apache/hivemind/impl
MessageFormatter.java
Added: framework/src/test/org/apache/hivemind/impl
TestMessageFormatter.java
Log:
Certain classloaders (AntClassLoader for example) cause NullPointerException in impl.MessageFormatter.
PR: HIVEMIND-78
Revision Changes Path
1.133 +1 -0 jakarta-hivemind/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/status.xml,v
retrieving revision 1.132
retrieving revision 1.133
diff -u -r1.132 -r1.133
--- status.xml 4 May 2005 04:00:52 -0000 1.132
+++ status.xml 4 May 2005 13:19:08 -0000 1.133
@@ -31,6 +31,7 @@
</todo>
<changes>
<release version="1.1-beta-2" date="unreleased">
+ <action type="fix" dev="JC" fixes-bug="HIVEMIND-78" >Certain classloaders (AntClassLoader for example) cause NullPointerException in impl.MessageFormatter.</action>
<action type="add" dev="JC" fixes-bug="HIVEMIND-91" >Add getModuleMessages() to Registry.</action>
<action type="fix" dev="JC" fixes-bug="HIVEMIND-105" >ServiceImplementationFactoryParameters.getFirstParameter should cope better with zero parameters.</action>
<action type="fix" dev="JC" fixes-bug="HIVEMIND-101" >OrdererMessages.exception uses wrong message key.</action>
1.1 jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestMessageFormatter.java
Index: TestMessageFormatter.java
===================================================================
// Copyright 2005 The Apache Software Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package org.apache.hivemind.impl;
import java.net.URL;
import java.net.URLClassLoader;
import org.apache.hivemind.test.HiveMindTestCase;
/**
* @author James Carman
* @version 1.0
*/
public class TestMessageFormatter extends HiveMindTestCase
{
public void testWithNoPackage() throws Exception
{
final ClassLoader loader = new NoPackageClassLoader();
new MessageFormatter(loader.loadClass(TestMessageFormatter.class
.getName()), "MessageFinder");
}
private class NoPackageClassLoader extends URLClassLoader
{
public NoPackageClassLoader()
{
super( new URL[] { TestMessageFormatter.class.getProtectionDomain().getCodeSource().getLocation() } );
}
protected Package getPackage(String name)
{
return null;
}
public Class loadClass(String name) throws ClassNotFoundException
{
try
{
return findClass( name );
}
catch( ClassNotFoundException e )
{
return super.loadClass(name);
}
}
}
}
1.10 +17 -1 jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFormatter.java
Index: MessageFormatter.java
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/impl/MessageFormatter.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- MessageFormatter.java 29 Apr 2005 07:40:54 -0000 1.9
+++ MessageFormatter.java 4 May 2005 13:19:08 -0000 1.10
@@ -46,7 +46,7 @@
public MessageFormatter(Log log, Class referenceClass, String name)
{
- this(log, referenceClass.getPackage().getName() + "." + name);
+ this(log, getResourceBundleName( referenceClass, name ) );
}
public MessageFormatter(Log log, String bundleName)
@@ -71,4 +71,20 @@
{
return Locale.getDefault();
}
+
+ private static String getResourceBundleName( Class referenceClass, String name )
+ {
+ String packageName = null;
+ if( referenceClass.getPackage() != null )
+ {
+ packageName = referenceClass.getPackage().getName();
+ }
+ else
+ {
+ final int lastDotIndex = referenceClass.getName().lastIndexOf( '.' );
+ packageName = ( lastDotIndex == -1 ? "" : referenceClass.getName().substring( 0, lastDotIndex ) );
+
+ }
+ return packageName.equals( "" ) ? name : packageName + "." + name;
+ }
}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org