Changeset 18192 in josm


Ignore:
Timestamp:
2021-09-03T02:11:51+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #21279 - fix NPE (patch by marcello, modified)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/tagging/ac/AutoCompComboBox.java

    r18173 r18192  
    105105        public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr)
    106106                throws BadLocationException {
    107             int newLen = fb.getDocument().getLength() + string.length();
    108             if (maxTextLength == -1 || newLen <= maxTextLength ||
    109                     // allow longer text while composing characters or it will be hard to compose
    110                     // the last characters before the limit
    111                     ((attr != null) && attr.isDefined(StyleConstants.ComposedTextAttribute))) {
     107            if (mustInsertOrReplace(fb, 0, string, attr)) {
    112108                super.insertString(fb, offset, string, attr);
    113109            }
     
    117113        public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr)
    118114                throws BadLocationException {
    119             int newLen = fb.getDocument().getLength() - length + string.length();
    120             if (maxTextLength == -1 || newLen <= maxTextLength ||
     115            if (mustInsertOrReplace(fb, length, string, attr)) {
     116                super.replace(fb, offset, length, string, attr);
     117            }
     118        }
     119
     120        private boolean mustInsertOrReplace(FilterBypass fb, int length, String string, AttributeSet attr) {
     121            int newLen = fb.getDocument().getLength() - length + ((string == null) ? 0 : string.length());
     122            return (maxTextLength == -1 || newLen <= maxTextLength ||
    121123                    // allow longer text while composing characters or it will be hard to compose
    122124                    // the last characters before the limit
    123                     ((attr != null) && attr.isDefined(StyleConstants.ComposedTextAttribute))) {
    124                 super.replace(fb, offset, length, string, attr);
    125             }
     125                    ((attr != null) && attr.isDefined(StyleConstants.ComposedTextAttribute)));
    126126        }
    127127    }
Note: See TracChangeset for help on using the changeset viewer.