----- Original Message ----- > This patch fixes NPE for the following Malva test cases: > > assertEquals("false", String.format("%b", (Object[])null)); > assertEquals("null", String.format("%h", (Object[])null)); > assertEquals("null", String.format("%s", (Object[])null)); > assertEquals("null", String.format("%c", (Object[])null)); > assertEquals("null", String.format("%d", (Object[])null)); > assertEquals("null", String.format("%o", (Object[])null)); > assertEquals("null", String.format("%x", (Object[])null)); > > Signed-off-by: Pekka Enberg <penb...@kernel.org> > --- > ChangeLog | 10 ++++++++++ > java/util/Formatter.java | 21 ++++++++++++++++++--- > 2 files changed, 28 insertions(+), 3 deletions(-) > > diff --git a/ChangeLog b/ChangeLog > index 384918b..746a1f7 100644 > --- a/ChangeLog > +++ b/ChangeLog > @@ -1,5 +1,15 @@ > 2012-03-15 Pekka Enberg <penb...@kernel.org> > > + * java/util/Formatter.java: > + (icharacterFormat(Object,int,int,int,char): > + Fix NullPointerException for null characters. > + (basicIntegralConversion(Object, int, int, int, int, char): > + Fix NullPointerException for null integers. > + (format(Locale, String, Object...)): > + Fix NullPointerException for null object. > + > +2012-03-15 Pekka Enberg <penb...@kernel.org> > + > * java/lang/String.java: > (codePointAt(int))): Fix exception type. > (codePointBefore(int)): Fix exception type. > diff --git a/java/util/Formatter.java b/java/util/Formatter.java > index 62f6845..466fab5 100644 > --- a/java/util/Formatter.java > +++ b/java/util/Formatter.java > @@ -678,6 +678,12 @@ public final class Formatter > conversion); > noPrecision(precision); > > + if (arg == null) > + { > + genericFormat("null", flags, width, precision); > + return; > + } > + > int theChar; > if (arg instanceof Character) > theChar = ((Character) arg).charValue(); > @@ -748,6 +754,12 @@ public final class Formatter > int radix, char > conversion) > { > assert radix == 8 || radix == 10 || radix == 16; > + > + if (arg == null) > + { > + return new CPStringBuilder("null"); > + } > + > noPrecision(precision); > > // Some error checking. > @@ -1353,9 +1365,12 @@ public final class Formatter > argumentIndex = previousArgumentIndex; > // Argument indices start at 1 but array indices at > 0. > --argumentIndex; > - if (argumentIndex < 0 || argumentIndex >= > args.length) > - throw new > MissingFormatArgumentException(format.substring(start, index)); > - argument = args[argumentIndex]; > + if (args != null) > + { > + if (argumentIndex < 0 || argumentIndex >= > args.length) > + throw new > MissingFormatArgumentException(format.substring(start, index)); > + argument = args[argumentIndex]; > + } > } > > switch (conversion) > -- > 1.7.7.6 > > >
This one looks ok now. Good to go. -- Andrew :) Free Java Software Engineer Red Hat, Inc. (http://www.redhat.com) PGP Key: 248BDC07 (https://keys.indymedia.org/) Fingerprint = EC5A 1F5E C0AD 1D15 8F1F 8F91 3B96 A578 248B DC07