commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benedikt Ritter <>
Subject [SANDBOX][BeanUtils2] Unexpected behavior on Assertions.checkArgument(boolean, String, Object..)
Date Wed, 25 Jan 2012 20:53:28 GMT

I'm refactoring AssertionsTest to match the discussed best practices. I 
wrote a test method for checkArgument(boolean Argument, String 
errorTemplate, Object.. errorArgs):

@Test( expected = NullPointerException.class )
public void checkArgumentFalseStringNull()
     checkArgument( false, ERROR_MSG, (Object[]) null );

The javadoc for checkArgument is:
@throws NullPointerException if the check fails and either {@code
     errorMessageTemplate} or {@code errorMessageArgs} is null (don't let
     this happen)

but when I execute the test, it fails because I'm getting an 
IllegalStateException (instead of the expected NPE). Although this is 
expected if false is passed in, it violates the contract described in 
the javadoc. I'm not sure what to do now. I could either change the 
implementation of checkArgument to throw the correct exception if 
errorArgs is null or change the javadoc (remove the second part of the 
throws declaration).
I would prefer the latter. But then one thing has to be paid attention 
to: If we call checkArgument(false, ERROR_MSG) and ERROR_MSG contains 
any placeholders ("%s") and there are no errorArgs given, a 
java.util.MissingArgumentFormatException will be thrown. So we would 
have to deal with that.

Any thoughts?

All the best

PS: this also applies to checkState(boolean state, String errorTemplate, 
Object... errorArgs)

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message