Ticket #6771: 6771.patch

File 6771.patch, 1.8 KB (added by simon04, 14 years ago)

patch to avoid NPE when calling tr() with null parameter

  • src/org/openstreetmap/josm/tools/I18n.java

    diff --git a/src/org/openstreetmap/josm/tools/I18n.java b/src/org/openstreetmap/josm/tools/I18n.java
    index 03aaf9a..03d5daf 100644
    a b public class I18n {  
    146146     * @see #trnc
    147147     */
    148148    public static final String tr(String text, Object... objects) {
     149        if (text == null)
     150            return null;
    149151        return MessageFormat.format(gettext(text, null), objects);
    150152    }
    151153
    public class I18n {  
    219221     * @see #trnc
    220222     */
    221223    public static final String trn(String singularText, String pluralText, long n, Object... objects) {
    222         return MessageFormat.format(gettextn(singularText, pluralText, null, n), objects);
     224        String text = gettextn(singularText, pluralText, null, n);
     225        if (text == null)
     226            return null;
     227        return MessageFormat.format(text, objects);
    223228    }
    224229
    225230    /**
    public class I18n {  
    246251     * @see #trn
    247252     */
    248253    public static final String trnc(String context, String singularText, String pluralText, long n, Object... objects) {
    249         return MessageFormat.format(gettextn(singularText, pluralText, context, n), objects);
     254        String text = gettextn(singularText, pluralText, context, n);
     255        if (text == null)
     256            return null;
     257        return MessageFormat.format(text, objects);
    250258    }
    251259
    252260    private static final String gettext(String text, String ctx, boolean lazy)
    public class I18n {  
    283291
    284292    private static final String gettextn(String text, String plural, String ctx, long num)
    285293    {
     294        if (text == null)
     295            return null;
    286296        int i;
    287297        if(ctx == null && text.startsWith("_:") && (i = text.indexOf("\n")) >= 0)
    288298        {