Appending strings in Assert.check

Andreas Lundblad andreas.lundblad at oracle.com
Thu Dec 11 15:11:40 UTC 2014


I recently discovered that the RunCodingRules test chokes on statements such as

    Assert.check(isFound, "Value not found: " + value);

due to the string concatenation in the second argument. I understand the purpose of this rule, but people (at least I) really want to be able to compose strings in error messages, and I bet the rule will lead to things like

    Assert.check(isFound, String.format("Value not found: %s", value));

or

   Assert.check(isFound, new StringBuilder("Value not found: " + value));

which obviously defeats the purpose of the rule.

I suggest we add a vararg check-method which accepts a format string + arguments, so we can write

    Assert.check(isFound, "Value not found: %s", value);

(and carry out the formatting if assertions are enabled and the condition is false)?

-- Andreas


More information about the compiler-dev mailing list