Changeset 14441 in josm


Ignore:
Timestamp:
2018-11-22T00:34:59+01:00 (5 months ago)
Author:
Don-vip
Message:

fix SonarQube issues

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java

    r13901 r14441  
    2626import javax.xml.transform.stream.StreamSource;
    2727import javax.xml.validation.Schema;
    28 import javax.xml.validation.Validator;
    2928
    3029import org.openstreetmap.josm.io.CachedFile;
     
    9796        try (CachedFile cf = new CachedFile("resource://data/preferences.xsd"); InputStream xsdStream = cf.getInputStream()) {
    9897            Schema schema = XmlUtils.newXmlSchemaFactory().newSchema(new StreamSource(xsdStream));
    99             Validator validator = schema.newValidator();
    100             validator.validate(new StreamSource(in));
     98            XmlUtils.newSafeValidator(schema).validate(new StreamSource(in));
    10199        }
    102100    }
  • trunk/src/org/openstreetmap/josm/tools/OptionParser.java

    r14435 r14441  
    6464    public OptionParser addFlagParameter(String optionName, Runnable handler) {
    6565        checkOptionName(optionName);
    66         availableOptions.put("--" + optionName, new AvailableOption() {
    67             @Override
    68             public void runFor(String parameter) {
    69                 handler.run();
    70             }
    71         });
     66        availableOptions.put("--" + optionName, parameter -> handler.run());
    7267        return this;
    7368    }
  • trunk/src/org/openstreetmap/josm/tools/XmlUtils.java

    r14348 r14441  
    1414import javax.xml.transform.TransformerConfigurationException;
    1515import javax.xml.transform.TransformerFactory;
     16import javax.xml.validation.Schema;
    1617import javax.xml.validation.SchemaFactory;
    1718import javax.xml.validation.SchemaFactoryConfigurationError;
     19import javax.xml.validation.Validator;
    1820
    1921import org.w3c.dom.Document;
     
    2325import org.xml.sax.InputSource;
    2426import org.xml.sax.SAXException;
     27import org.xml.sax.SAXNotRecognizedException;
     28import org.xml.sax.SAXNotSupportedException;
    2529import org.xml.sax.helpers.DefaultHandler;
    2630
     
    146150
    147151    /**
     152     * Returns a new secure {@link Validator}.
     153     * @param schema XML schema
     154     * @return a new secure {@link Validator}
     155     * @since 14441
     156     */
     157    public static Validator newSafeValidator(Schema schema) {
     158        Validator validator = schema.newValidator();
     159        try {
     160            validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
     161            validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
     162        } catch (SAXNotRecognizedException | SAXNotSupportedException e) {
     163            // All implementations that implement JAXP 1.5 or newer are required to support these two properties
     164            Logging.trace(e);
     165        }
     166        return validator;
     167    }
     168
     169    /**
    148170     * Get the first child element
    149171     * @param parent parent node
Note: See TracChangeset for help on using the changeset viewer.