Changeset 5635 in josm


Ignore:
Timestamp:
2012-12-27T00:48:51+01:00 (12 years ago)
Author:
Don-vip
Message:

fix #8278 - Robustness in capabilities cache parsing at startup

File:
1 edited

Legend:

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

    r5587 r5635  
    2525import java.util.HashMap;
    2626
     27import javax.xml.parsers.ParserConfigurationException;
    2728import javax.xml.parsers.SAXParserFactory;
    2829
     
    4041import org.xml.sax.InputSource;
    4142import org.xml.sax.SAXException;
     43import org.xml.sax.SAXParseException;
    4244import org.xml.sax.helpers.DefaultHandler;
    4345
     
    216218        cancel = false;
    217219        try {
    218             String s = new CapabilitiesCache(monitor, fastFail).updateIfRequiredString();
    219             InputSource inputSource = new InputSource(new StringReader(s));
    220             SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
     220            CapabilitiesCache cache = new CapabilitiesCache(monitor, fastFail);
     221            try {
     222                initializeCapabilities(cache.updateIfRequiredString());
     223            } catch (SAXParseException parseException) {
     224                // XML parsing may fail if JOSM previously stored a corrupted capabilities document (see #8278)
     225                // In that case, force update and try again
     226                initializeCapabilities(cache.updateForceString());
     227            }
    221228            if (capabilities.supportsVersion("0.6")) {
    222229                version = "0.6";
     
    261268            throw new OsmApiInitializationException(e);
    262269        }
     270    }
     271   
     272    private void initializeCapabilities(String xml) throws SAXException, IOException, ParserConfigurationException {
     273        InputSource inputSource = new InputSource(new StringReader(xml));
     274        SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
    263275    }
    264276
Note: See TracChangeset for help on using the changeset viewer.