proposal for performance/usability optimisations in commons.lang.Validate

2009-05-02 Thread Mark Struberg

Hi!

I'm a long time user (and big fan) of commons.lang.Validate because it's a very 
neat pattern for getting stable software modules.

I'm PMC member on Apache OpenWebBeans and currently also writing the 
maven-scm-provider-jgit (JGIT is a native Java implementation of GIT). Since 
jgit-core (the part of EGIT we use for the maven-scm-provider-jgit) is BSD and 
Shawn likes to have not too much external dependencies, I started writing my 
own little Validate helper class and had a hopefully good idea which imho would 
also be a good extension to commons.lang.Validate:

A main problem on validation is the message creation which costs a lot of 
String operations and therefor also garbage collection. I've now seen that the 
latest version in SVN has an additional object parameter for a few functions 
which addresses this problem. My proposal now goes even further but requires 
java-5 since it uses ellipsis notation.

If msgObject[0] is a String java.text.MessageFormat will be used for creating 
the failure message, e.g.
Validate.notNull(nullInt, "testMessageText Integer={0} btw! and Integer2={1}.", 
new Integer(42), new Integer(43));

example for isTrue with message construction:

/**
 * Validate that b is true
 * 
 * @param b boolean to validate
 * @param msgObjects additional Objects added as text message to the 
InvalidArgumentException
 */
public static void isTrue(boolean b, Object... msgObjects) {
if (!b) {
throw new IllegalArgumentException(getMessage(msgObjects));
}
}

/**
 * private helper function to create an error message from the given Objects
 * If the first object in msgObjects is of type {...@code String} then 
 * {...@code MessageFormat} will be used to format the output message.
 * 
 * @param msgObjects
 * @return concatenated String representation of all the objects
 */
private static String getMessage(Object... msgObjects) {
if (msgObjects.length > 0 && msgObjects[0] instanceof String) {
MessageFormat form = new MessageFormat((String) msgObjects[0]);
Object[] params = new Object[msgObjects.length - 1];
System.arraycopy(msgObjects, 1, params, 0, msgObjects.length - 
1);
return form.format(params);
}
else {
StringBuffer sb = new StringBuffer("Validation failed: [");
for(int i = 0; i < msgObjects.length; i++) {
if (i > 0) {
sb.append(' ');
}
sb.append(msgObjects[i]);
}
sb.append(']');
return sb.toString();
}
}

I've tested those functions against 'old' Validate handling to ensure that 
there are no performance side effects with Java ellipsis handling, and the 
performance win is huge [1]. The ellipsis Version only takes < 5% of the time 
of the 'old' handling.

WDYT? 
a.) Is the implementation ok?
b.) Will there be a java-5 only version of commons.lang in the near future?
c.) Imho we could replace the 1-parameter versions with the proper ellipsis 
functions and we are still compile compatible. But I'm not sure if we stay 
binary-compatible (needs to be tested).

I wrote a Validate class this way for jgit-core [2] but also have to like this 
features in our owns commons.lang.Validate if possible!


txs and LieGrue,
strub

[1] http://pastebin.com/m2cf887a9

[2] 
http://github.com/sonatype/JGit/blob/2ab3a576fa67145d6a9f66efd7437c52d567eb68/org.spearce.jgit/src/org/spearce/jgit/util/Validate.java





-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[g...@vmgump]: Project commons-jelly-tags-ojb (in module commons-jelly) failed

2009-05-02 Thread commons-jelly-tags-ojb development
To whom it may engage...

This is an automated request, but not an unsolicited one. For 
more information please visit http://gump.apache.org/nagged.html, 
and/or contact the folk at gene...@gump.apache.org.

Project commons-jelly-tags-ojb has an issue affecting its community integration.
This issue affects 1 projects,
 and has been outstanding for 6 runs.
The current state of this project is 'Failed', with reason 'Configuration 
Failed'.
For reference only, the following projects are affected by this:
- commons-jelly-tags-ojb :  Commons Jelly


Full details are available at:

http://vmgump.apache.org/gump/public/commons-jelly/commons-jelly-tags-ojb/index.html

That said, some information snippets are provided here.

The following annotations (debug/informational/warning/error messages) were 
provided:
 -DEBUG- Sole output [commons-jelly-tags-ojb-02052009.jar] identifier set to 
project name
 -ERROR- No such project [db-ojb-from-packages] for property.
 -ERROR- Cannot resolve output/outputpath of *unknown* [db-ojb-from-packages]
 -ERROR- Unhandled Property: maven.jar.ojb on: Maven on 
Project:commons-jelly-tags-ojb
 -DEBUG- Dependency on xml-xerces exists, no need to add for property 
maven.jar.xerces.
 -INFO- Failed with reason configuration failed
 -ERROR- Bad Dependency. Project: db-ojb-from-packages : unknown to *this* 
workspace 
 -INFO- Failed to extract fallback artifacts from Gump Repository

To subscribe to this information via syndicated feeds:
- RSS: 
http://vmgump.apache.org/gump/public/commons-jelly/commons-jelly-tags-ojb/rss.xml
- Atom: 
http://vmgump.apache.org/gump/public/commons-jelly/commons-jelly-tags-ojb/atom.xml

== Gump Tracking Only ===
Produced by Gump version 2.3.
Gump Run 0502052009, vmgump:vmgump-public:0502052009
Gump E-mail Identifier (unique within run) #39.

--
Apache Gump
http://gump.apache.org/ [Instance: vmgump]

-
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org



[g...@vmgump]: Project commons-configuration-test (in module apache-commons) failed

2009-05-02 Thread Gump
To whom it may engage...

This is an automated request, but not an unsolicited one. For 
more information please visit http://gump.apache.org/nagged.html, 
and/or contact the folk at gene...@gump.apache.org.

Project commons-configuration-test has an issue affecting its community 
integration.
This issue affects 1 projects,
 and has been outstanding for 52 runs.
The current state of this project is 'Failed', with reason 'Build Failed'.
For reference only, the following projects are affected by this:
- commons-configuration-test :  Apache Commons


Full details are available at:

http://vmgump.apache.org/gump/public/apache-commons/commons-configuration-test/index.html

That said, some information snippets are provided here.

The following annotations (debug/informational/warning/error messages) were 
provided:
 -WARNING- Overriding Maven2 settings: 
[/srv/gump/public/workspace/apache-commons/configuration/gump_mvn_settings.xml]
 -DEBUG- (Gump generated) Maven2 Settings in: 
/srv/gump/public/workspace/apache-commons/configuration/gump_mvn_settings.xml
 -INFO- Failed with reason build failed
 -DEBUG- Maven POM in: 
/srv/gump/public/workspace/apache-commons/configuration/pom.xml
 -INFO- Project Reports in: 
/srv/gump/public/workspace/apache-commons/configuration/target/surefire-reports



The following work was performed:
http://vmgump.apache.org/gump/public/apache-commons/commons-configuration-test/gump_work/build_apache-commons_commons-configuration-test.html
Work Name: build_apache-commons_commons-configuration-test (Type: Build)
Work ended in a state of : Failed
Elapsed: 1 min 36 secs
Command Line: mvn --batch-mode --settings 
/srv/gump/public/workspace/apache-commons/configuration/gump_mvn_settings.xml 
test 
[Working Directory: /srv/gump/public/workspace/apache-commons/configuration]
CLASSPATH: 
/usr/lib/jvm/java-6-sun/lib/tools.jar:/srv/gump/public/workspace/apache-commons/configuration/target/commons-configuration-1.7-SNAPSHOT.jar
-
  testAddNodesCopy(org.apache.commons.configuration.TestXMLConfiguration)
  testInitCopy(org.apache.commons.configuration.TestXMLConfiguration)
  testSetRootAttribute(org.apache.commons.configuration.TestXMLConfiguration)
  testLoadAndSaveFromFile(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveToURL(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveToStream(org.apache.commons.configuration.TestXMLConfiguration)
  testAutoSave(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveAttributes(org.apache.commons.configuration.TestXMLConfiguration)
  testCloneWithSave(org.apache.commons.configuration.TestXMLConfiguration)
  testEmptyElements(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveWithEncoding(org.apache.commons.configuration.TestXMLConfiguration)
  
testSaveWithNullEncoding(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveWithDoctype(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveWithDoctypeIDs(org.apache.commons.configuration.TestXMLConfiguration)
  testSubsetWithReload(org.apache.commons.configuration.TestXMLConfiguration)
  
testConfigurationAtWithReload(org.apache.commons.configuration.TestXMLConfiguration)
  
testConfigurationsAtWithReload(org.apache.commons.configuration.TestXMLConfiguration)
  testGetKeysWithReload(org.apache.commons.configuration.TestXMLConfiguration)
  testSetTextRootElement(org.apache.commons.configuration.TestXMLConfiguration)
  
testClearTextRootElement(org.apache.commons.configuration.TestXMLConfiguration)
  
testAutoSaveWithSubnodeConfig(org.apache.commons.configuration.TestXMLConfiguration)
  
testAutoSaveWithSubSubnodeConfig(org.apache.commons.configuration.TestXMLConfiguration)
  
testSaveDelimiterParsingDisabled(org.apache.commons.configuration.TestXMLConfiguration)
  
testSaveDelimiterParsingDisabledAttrs(org.apache.commons.configuration.TestXMLConfiguration)
  
testMultipleAttrValuesEscaped(org.apache.commons.configuration.TestXMLConfiguration)
  
testAutoSaveWithReloadingStrategy(org.apache.commons.configuration.TestXMLConfiguration)
  testAutoSaveAddNodes(org.apache.commons.configuration.TestXMLConfiguration)
  testAddNodesAndSave(org.apache.commons.configuration.TestXMLConfiguration)
  testRegisterEntityId(org.apache.commons.configuration.TestXMLConfiguration)
  
testSaveAfterCreateWithCopyConstructor(org.apache.commons.configuration.TestXMLConfiguration)
  testCopyRootName(org.apache.commons.configuration.TestXMLConfiguration)
  
testCopyRootNameNoDocument(org.apache.commons.configuration.TestXMLConfiguration)
  testSaveWithValidation(org.apache.commons.configuration.TestXMLConfiguration)
  
testSaveWithValidationFailure(org.apache.commons.configuration.TestXMLConfiguration)

Tests run: 1418, Failures: 0, Errors: 52, Skipped: 0

[INFO] 
[ERROR] BUILD FAILURE
[INFO] --