Ignore:
Timestamp:
2015-05-02T00:55:19+02:00 (9 years ago)
Author:
Don-vip
Message:

fix potential NPEs and Sonar issues related to serialization

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/AbstractParser.java

    r8148 r8308  
    2525 */
    2626public abstract class AbstractParser extends DefaultHandler {
    27    
     27
    2828    /** the current primitive to be read */
    2929    protected HistoryOsmPrimitive currentPrimitive;
     
    3434        this.locator = locator;
    3535    }
    36    
     36
    3737    protected abstract void throwException(String message) throws SAXException;
     38
     39    protected abstract void throwException(String message, Exception e) throws SAXException;
    3840
    3941    protected final long getMandatoryAttributeLong(Attributes attr, String name) throws SAXException {
     
    4648            l = Long.parseLong(v);
    4749        } catch(NumberFormatException e) {
    48             throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v));
     50            throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v), e);
    4951        }
    5052        if (l < 0) {
     
    6264            l = Long.parseLong(v);
    6365        } catch(NumberFormatException e) {
    64             throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v));
     66            throwException(tr("Illegal value for mandatory attribute ''{0}'' of type long. Got ''{1}''.", name, v), e);
    6567        }
    6668        if (l < 0) {
     
    7981            d = Double.parseDouble(v);
    8082        } catch(NumberFormatException e) {
    81             throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v));
     83            throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v), e);
    8284        }
    8385        return d;
     
    102104        return false; // not reached
    103105    }
    104    
     106
    105107    protected final HistoryOsmPrimitive createPrimitive(Attributes atts, OsmPrimitiveType type) throws SAXException {
    106108        long id = getMandatoryAttributeLong(atts,"id");
     
    152154        currentPrimitive = createPrimitive(atts, OsmPrimitiveType.WAY);
    153155    }
    154    
     156
    155157    protected final void startRelation(Attributes atts) throws SAXException {
    156158        currentPrimitive = createPrimitive(atts, OsmPrimitiveType.RELATION);
     
    175177            type = OsmPrimitiveType.fromApiTypeName(v);
    176178        } catch(IllegalArgumentException e) {
    177             throwException(tr("Illegal value for mandatory attribute ''{0}'' of type OsmPrimitiveType. Got ''{1}''.", "type", v));
     179            throwException(tr("Illegal value for mandatory attribute ''{0}'' of type OsmPrimitiveType. Got ''{1}''.", "type", v), e);
    178180        }
    179181        String role = getMandatoryAttributeString(atts, "role");
     
    181183        ((HistoryRelation)currentPrimitive).addMember(member);
    182184    }
    183    
     185
    184186    protected final boolean doStartElement(String qName, Attributes atts) throws SAXException {
    185187        switch (qName) {
Note: See TracChangeset for help on using the changeset viewer.