Changeset 10235 in josm
- Timestamp:
- 2016-05-17T02:02:30+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/cache/JCSCacheManager.java
r10169 r10235 158 158 159 159 @SuppressWarnings("unchecked") 160 private static <K, V> CacheAccess<K, V> getCacheInner(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) { 160 private static <K, V> CacheAccess<K, V> getCacheInner(String cacheName, int maxMemoryObjects, int maxDiskObjects, String cachePath) 161 throws IOException { 161 162 CompositeCache<K, V> cc = cacheManager.getCache(cacheName, getCacheAttributes(maxMemoryObjects)); 162 163 … … 169 170 cc.setAuxCaches(new AuxiliaryCache[]{diskCache}); 170 171 } 172 } catch (IOException e) { 173 throw e; 171 174 } catch (Exception e) { 172 throw new RuntimeException(e);175 throw new IOException(e); 173 176 } 174 177 } -
trunk/src/org/openstreetmap/josm/data/imagery/CachedTileLoaderFactory.java
r9067 r10235 4 4 import java.io.File; 5 5 import java.lang.reflect.Constructor; 6 import java.lang.reflect.InvocationTargetException;7 6 import java.util.Map; 8 7 import java.util.concurrent.ConcurrentHashMap; … … 33 32 * @param cache cache instance which will be used by tile loaders created by this tile loader 34 33 * @param tileLoaderClass tile loader class that will be created 35 * 34 * @throws IllegalArgumentException if a suitable constructor cannot be found for {@code tileLoaderClass} 36 35 */ 37 36 public CachedTileLoaderFactory(ICacheAccess<String, BufferedImageCacheEntry> cache, Class<? extends TileLoader> tileLoaderClass) { … … 46 45 } catch (NoSuchMethodException | SecurityException e) { 47 46 Main.warn(e); 48 throw new RuntimeException(e);47 throw new IllegalArgumentException(e); 49 48 } 50 49 } … … 88 87 readTimeout, 89 88 headers); 90 } catch (I nstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {89 } catch (IllegalArgumentException e) { 91 90 Main.warn(e); 92 throw new RuntimeException(e); 91 throw e; 92 } catch (ReflectiveOperationException e) { 93 Main.warn(e); 94 throw new IllegalArgumentException(e); 93 95 } 94 96 } -
trunk/src/org/openstreetmap/josm/data/preferences/ListListSetting.java
r9759 r10235 74 74 if (value != null) { 75 75 if (value.contains(null)) 76 throw new RuntimeException("Error: Null as list element in preference setting");76 throw new IllegalArgumentException("Error: Null as list element in preference setting"); 77 77 for (Collection<String> lst : value) { 78 78 if (lst.contains(null)) { 79 throw new RuntimeException("Error: Null as inner list element in preference setting");79 throw new IllegalArgumentException("Error: Null as inner list element in preference setting"); 80 80 } 81 81 } -
trunk/src/org/openstreetmap/josm/data/preferences/ListSetting.java
r9759 r10235 44 44 private void consistencyTest() { 45 45 if (value != null && value.contains(null)) 46 throw new RuntimeException("Error: Null as list element in preference setting");46 throw new IllegalArgumentException("Error: Null as list element in preference setting"); 47 47 } 48 48 -
trunk/src/org/openstreetmap/josm/data/preferences/MapListSetting.java
r9759 r10235 73 73 return; 74 74 if (value.contains(null)) 75 throw new RuntimeException("Error: Null as list element in preference setting");75 throw new IllegalArgumentException("Error: Null as list element in preference setting"); 76 76 for (Map<String, String> map : value) { 77 77 if (map.keySet().contains(null)) 78 throw new RuntimeException("Error: Null as map key in preference setting");78 throw new IllegalArgumentException("Error: Null as map key in preference setting"); 79 79 if (map.values().contains(null)) 80 throw new RuntimeException("Error: Null as map value in preference setting");80 throw new IllegalArgumentException("Error: Null as map value in preference setting"); 81 81 } 82 82 } -
trunk/src/org/openstreetmap/josm/data/preferences/PreferencesReader.java
r9978 r10235 31 31 import org.openstreetmap.josm.Main; 32 32 import org.openstreetmap.josm.io.CachedFile; 33 import org.openstreetmap.josm.io.XmlStreamParsingException; 33 34 import org.xml.sax.SAXException; 34 35 … … 37 38 */ 38 39 public class PreferencesReader { 39 40 private static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";41 40 42 41 private final SortedMap<String, Setting<?>> settings = new TreeMap<>(); … … 118 117 } 119 118 119 /** 120 * Parse preferences. 121 * @throws XMLStreamException if any XML parsing error occurs 122 * @throws IOException if any I/O error occurs 123 */ 120 124 public void parse() throws XMLStreamException, IOException { 121 125 if (reader != null) { … … 168 172 switch(localName) { 169 173 case "tag": 170 Setting setting; 174 StringSetting setting; 171 175 if (defaults && isNil()) { 172 176 setting = new StringSetting(null); … … 221 225 List<Map<String, String>> maps = null; 222 226 if (defaults && isNil()) { 223 Setting setting; 227 Setting<?> setting; 224 228 switch (name) { 225 229 case "lists": … … 268 272 } 269 273 } 270 Setting setting; 274 Setting<?> setting; 271 275 if (entries != null) { 272 276 setting = new ListSetting(Collections.unmodifiableList(entries)); … … 337 341 */ 338 342 private boolean isNil() { 339 String nil = parser.getAttributeValue(X SI_NS, "nil");343 String nil = parser.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "nil"); 340 344 return "true".equals(nil) || "1".equals(nil); 341 345 } 342 346 343 347 /** 344 * Throw RuntimeException with line and column number.348 * Throw XmlStreamParsingException with line and column number. 345 349 * 346 350 * Only use this for errors that should not be possible after schema validation. 347 351 * @param msg the error message 348 * /349 private void throwException(String msg) {350 throw new RuntimeException(msg + tr(" (at line {0}, column {1})",351 parser.getLocation().getLineNumber(), parser.getLocation().getColumnNumber()));352 * @throws XmlStreamParsingException always 353 */ 354 private void throwException(String msg) throws XmlStreamParsingException { 355 throw new XmlStreamParsingException(msg, parser.getLocation()); 352 356 } 353 357 } -
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r10212 r10235 775 775 ret.put("oslo", parseAngle("10d43'22.5\"E", null)); 776 776 } catch (ProjectionConfigurationException ex) { 777 throw new RuntimeException();777 throw new IllegalStateException(ex); 778 778 } 779 779 return ret; -
trunk/src/org/openstreetmap/josm/data/projection/proj/AbstractProj.java
r9992 r10235 138 138 for (i = MAXIMUM_ITERATIONS; true;) { // rarely goes over 5 iterations 139 139 if (--i < 0) { 140 throw new RuntimeException("Too many iterations");140 throw new IllegalStateException("Too many iterations"); 141 141 } 142 142 s = Math.sin(phi); … … 162 162 } 163 163 } 164 throw new RuntimeException("no convergence");164 throw new IllegalStateException("no convergence for ts="+ts); 165 165 } 166 166 -
trunk/src/org/openstreetmap/josm/data/projection/proj/AlbersEqualArea.java
r10001 r10235 126 126 rho = 0.0; 127 127 } else { 128 throw new RuntimeException();128 throw new AssertionError(); 129 129 } 130 130 } … … 184 184 } 185 185 } 186 throw new RuntimeException("no convergence for q="+qs);186 throw new IllegalStateException("no convergence for qs="+qs); 187 187 } 188 188 -
trunk/src/org/openstreetmap/josm/data/projection/proj/DoubleStereographic.java
r10001 r10235 100 100 while (abs(phi - phiprev) > EPSILON) { 101 101 if (++iteration > 10) 102 throw new RuntimeException("Too many iterations");102 throw new IllegalStateException("Too many iterations"); 103 103 phiprev = phi; 104 104 double psii = log(tan(phi/2 + PI/4) * pow((1 - e * sin(phi)) / (1 + e * sin(phi)), e/2)); -
trunk/src/org/openstreetmap/josm/data/projection/proj/PolarStereographic.java
r10001 r10235 163 163 phi0 = phi; 164 164 if (--i < 0) { 165 throw new RuntimeException("no convergence");165 throw new IllegalStateException("no convergence for x="+x+", y="+y); 166 166 } 167 167 } -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r10217 r10235 22 22 import java.security.AllPermission; 23 23 import java.security.CodeSource; 24 import java.security.GeneralSecurityException; 24 25 import java.security.KeyStoreException; 25 26 import java.security.NoSuchAlgorithmException; … … 413 414 try { 414 415 CertificateAmendment.addMissingCertificates(); 415 } catch (IOException ex) { 416 } catch (IOException | GeneralSecurityException ex) { 416 417 ex.printStackTrace(); 417 418 Main.warn(getErrorMessage(Utils.getRootCause(ex))); -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r10212 r10235 498 498 * Synchronously loads available sources and returns the parsed list. 499 499 * @return list of available sources 500 * @throws OsmTransferException in case of OSM transfer error 501 * @throws IOException in case of any I/O error 502 * @throws SAXException in case of any SAX error 500 503 */ 501 public final Collection<ExtendedSourceEntry> loadAndGetAvailableSources() { 502 try { 503 final SourceLoader loader = new SourceLoader(availableSourcesUrl, sourceProviders); 504 loader.realRun(); 505 return loader.sources; 506 } catch (IOException | SAXException | OsmTransferException ex) { 507 throw new RuntimeException(ex); 508 } 504 public final Collection<ExtendedSourceEntry> loadAndGetAvailableSources() throws SAXException, IOException, OsmTransferException { 505 final SourceLoader loader = new SourceLoader(availableSourcesUrl, sourceProviders); 506 loader.realRun(); 507 return loader.sources; 509 508 } 510 509 -
trunk/src/org/openstreetmap/josm/io/CertificateAmendment.java
r10088 r10235 11 11 import java.nio.file.Path; 12 12 import java.nio.file.Paths; 13 import java.security.GeneralSecurityException; 13 14 import java.security.InvalidAlgorithmParameterException; 14 import java.security.KeyManagementException;15 15 import java.security.KeyStore; 16 16 import java.security.KeyStoreException; 17 17 import java.security.MessageDigest; 18 import java.security.NoSuchAlgorithmException;19 import java.security.cert.CertificateException;20 18 import java.security.cert.CertificateFactory; 21 19 import java.security.cert.PKIXParameters; … … 59 57 * Add missing root certificates to the list of trusted certificates for TLS connections. 60 58 * @throws IOException if an I/O error occurs 59 * @throws GeneralSecurityException if a security error occurs 61 60 */ 62 public static void addMissingCertificates() throws IOException { 61 public static void addMissingCertificates() throws IOException, GeneralSecurityException { 63 62 if (!Main.pref.getBoolean("tls.add-missing-certificates", true)) 64 63 return; 65 KeyStore keyStore; 66 try { 67 keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); 68 } catch (KeyStoreException ex) { 69 throw new IOException(ex); 70 } 64 KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType()); 71 65 Path cacertsPath = Paths.get(System.getProperty("java.home"), "lib", "security", "cacerts"); 72 66 try (InputStream is = Files.newInputStream(cacertsPath)) { 73 67 keyStore.load(is, "changeit".toCharArray()); 74 } catch (NoSuchAlgorithmException ex) {75 throw new RuntimeException(ex);76 } catch (CertificateException ex) {77 throw new IOException(ex);78 68 } 79 69 80 CertificateFactory cf; 81 try { 82 cf = CertificateFactory.getInstance("X.509"); 83 } catch (CertificateException ex) { 84 throw new RuntimeException(ex); 85 } 70 CertificateFactory cf = CertificateFactory.getInstance("X.509"); 86 71 boolean certificateAdded = false; 87 72 for (int i = 0; i < CERT_AMEND.length; i++) { 88 CachedFile certCF = new CachedFile(CERT_AMEND[i]); 89 byte[] certBytes = certCF.getByteContent(); 90 ByteArrayInputStream certIS = new ByteArrayInputStream(certBytes); 91 X509Certificate cert; 92 93 try { 94 cert = (X509Certificate) cf.generateCertificate(certIS); 73 try (CachedFile certCF = new CachedFile(CERT_AMEND[i])) { 74 byte[] certBytes = certCF.getByteContent(); 75 ByteArrayInputStream certIS = new ByteArrayInputStream(certBytes); 76 X509Certificate cert = (X509Certificate) cf.generateCertificate(certIS); 95 77 MessageDigest md = MessageDigest.getInstance("SHA-256"); 96 78 String sha1 = Utils.toHexString(md.digest(cert.getEncoded())); 97 79 if (!SHA_HASHES[i].equals(sha1)) { 98 throw new RuntimeException(tr("Error adding certificate {0} - certificate fingerprint mismatch. Expected {1}, was {2}", 80 throw new IllegalStateException( 81 tr("Error adding certificate {0} - certificate fingerprint mismatch. Expected {1}, was {2}", 99 82 CERT_AMEND[i], 100 83 SHA_HASHES[i], … … 102 85 )); 103 86 } 104 } catch (CertificateException ex) { 105 throw new IOException(ex); 106 } catch (NoSuchAlgorithmException ex) { 107 throw new RuntimeException(ex); 108 } 109 if (certificateIsMissing(keyStore, cert)) { 110 if (Main.isDebugEnabled()) { 111 Main.debug(tr("Adding certificate for TLS connections: {0}", cert.getSubjectX500Principal().getName())); 87 if (certificateIsMissing(keyStore, cert)) { 88 if (Main.isDebugEnabled()) { 89 Main.debug(tr("Adding certificate for TLS connections: {0}", cert.getSubjectX500Principal().getName())); 90 } 91 String alias = "josm:" + new File(CERT_AMEND[i]).getName(); 92 keyStore.setCertificateEntry(alias, cert); 93 certificateAdded = true; 112 94 } 113 String alias = "josm:" + new File(CERT_AMEND[i]).getName();114 try {115 keyStore.setCertificateEntry(alias, cert);116 } catch (KeyStoreException ex) {117 throw new AssertionError(ex);118 }119 certificateAdded = true;120 95 } 121 96 } 122 97 123 98 if (certificateAdded) { 124 try { 125 TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 126 tmf.init(keyStore); 127 SSLContext sslContext = SSLContext.getInstance("TLS"); 128 sslContext.init(null, tmf.getTrustManagers(), null); 129 SSLContext.setDefault(sslContext); 130 } catch (NoSuchAlgorithmException | KeyStoreException | KeyManagementException ex) { 131 throw new RuntimeException(ex); 132 } 99 TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); 100 tmf.init(keyStore); 101 SSLContext sslContext = SSLContext.getInstance("TLS"); 102 sslContext.init(null, tmf.getTrustManagers(), null); 103 SSLContext.setDefault(sslContext); 133 104 } 134 105 } … … 139 110 * @param crt the certificate 140 111 * @return true, if the certificate is not contained in the keystore 112 * @throws InvalidAlgorithmParameterException if the keystore does not contain at least one trusted certificate entry 113 * @throws KeyStoreException if the keystore has not been initialized 141 114 */ 142 private static boolean certificateIsMissing(KeyStore keyStore, X509Certificate crt) { 143 PKIXParameters params; 144 try { 145 params = new PKIXParameters(keyStore); 146 } catch (KeyStoreException ex) { 147 throw new AssertionError(ex); 148 } catch (InvalidAlgorithmParameterException ex) { 149 throw new RuntimeException(ex); 150 } 115 private static boolean certificateIsMissing(KeyStore keyStore, X509Certificate crt) 116 throws KeyStoreException, InvalidAlgorithmParameterException { 117 PKIXParameters params = new PKIXParameters(keyStore); 151 118 String id = crt.getSubjectX500Principal().getName(); 152 119 for (TrustAnchor ta : params.getTrustAnchors()) { -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r10223 r10235 95 95 96 96 protected void throwException(String msg, Throwable th) throws XMLStreamException { 97 throw new OsmParsingException(msg, parser.getLocation(), th);97 throw new XmlStreamParsingException(msg, parser.getLocation(), th); 98 98 } 99 99 100 100 protected void throwException(String msg) throws XMLStreamException { 101 throw new OsmParsingException(msg, parser.getLocation());101 throw new XmlStreamParsingException(msg, parser.getLocation()); 102 102 } 103 103 … … 560 560 } 561 561 562 private static class OsmParsingException extends XMLStreamException {563 564 OsmParsingException(String msg, Location location) {565 super(msg); /* cannot use super(msg, location) because it messes with the message preventing localization */566 this.location = location;567 }568 569 OsmParsingException(String msg, Location location, Throwable th) {570 super(msg, th);571 this.location = location;572 }573 574 @Override575 public String getMessage() {576 String msg = super.getMessage();577 if (msg == null) {578 msg = getClass().getName();579 }580 if (getLocation() == null)581 return msg;582 msg += ' ' + tr("(at line {0}, column {1})", getLocation().getLineNumber(), getLocation().getColumnNumber());583 int offset = getLocation().getCharacterOffset();584 if (offset > -1) {585 msg += ". "+ tr("{0} bytes have been read", offset);586 }587 return msg;588 }589 }590 591 562 /** 592 563 * Exception thrown after user cancelation. 593 564 */ 594 private static final class OsmParsingCanceledException extends OsmParsingException implements ImportCancelException {565 private static final class OsmParsingCanceledException extends XmlStreamParsingException implements ImportCancelException { 595 566 /** 596 567 * Constructs a new {@code OsmParsingCanceledException}. … … 639 610 } catch (IllegalDataException e) { 640 611 throw e; 641 } catch ( OsmParsingException e) {612 } catch (XmlStreamParsingException e) { 642 613 throw new IllegalDataException(e.getMessage(), e); 643 614 } catch (XMLStreamException e) { -
trunk/src/org/openstreetmap/josm/tools/OverpassTurboQueryWizard.java
r10101 r10235 52 52 "}"); 53 53 } catch (ScriptException | IOException ex) { 54 throw new RuntimeException("Failed to initialize OverpassTurboQueryWizard", ex);54 throw new IllegalStateException("Failed to initialize OverpassTurboQueryWizard", ex); 55 55 } 56 56 } -
trunk/test/unit/org/openstreetmap/josm/JOSMFixture.java
r10222 r10235 7 7 import java.io.IOException; 8 8 import java.nio.file.Paths; 9 import java.security.GeneralSecurityException; 9 10 import java.text.MessageFormat; 10 11 import java.util.Locale; … … 98 99 try { 99 100 CertificateAmendment.addMissingCertificates(); 100 } catch (IOException ex) { 101 } catch (IOException | GeneralSecurityException ex) { 101 102 throw new RuntimeException(ex); 102 103 } -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/MapPaintPreferenceTestIT.java
r10222 r10235 5 5 import static org.junit.Assert.assertTrue; 6 6 7 import java.io.IOException;8 7 import java.util.Collection; 9 8 import java.util.Collections; … … 24 23 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSRule; 25 24 import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource; 26 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;27 25 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 28 26 … … 51 49 /** 52 50 * Test that available map paint styles are valid. 53 * @throws IOException if any I/O error occurs 54 * @throws ParseException if the config file does not match MapCSS syntax 51 * @throws Exception in case of error 55 52 */ 56 53 @Test 57 public void testValidityOfAvailableStyles() throws ParseException, IOException {54 public void testValidityOfAvailableStyles() throws Exception { 58 55 Collection<ExtendedSourceEntry> sources = new MapPaintPreference.MapPaintSourceEditor() 59 56 .loadAndGetAvailableSources(); -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java
r10222 r10235 46 46 /** 47 47 * Test that available tagging presets are valid. 48 * @throws Exception in case of error 48 49 */ 49 50 @Test 50 public void testValidityOfAvailablePresets() { 51 public void testValidityOfAvailablePresets() throws Exception { 51 52 Collection<ExtendedSourceEntry> sources = new TaggingPresetPreference.TaggingPresetSourceEditor() 52 53 .loadAndGetAvailableSources(); -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/validator/ValidatorTagCheckerRulesPreferenceTestIT.java
r9669 r10235 14 14 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker; 15 15 import org.openstreetmap.josm.data.validation.tests.MapCSSTagChecker.ParseResult; 16 import org.openstreetmap.josm.gui.mappaint.mapcss.parsergen.ParseException;17 16 import org.openstreetmap.josm.gui.preferences.SourceEditor.ExtendedSourceEntry; 18 17 … … 32 31 /** 33 32 * Test that available tag checker rules are valid. 34 * @throws IOException if any I/O error occurs 35 * @throws ParseException if the config file does not match MapCSS syntax 33 * @throws Exception in case of error 36 34 */ 37 35 @Test 38 public void testValidityOfAvailableRules() throws ParseException, IOException {36 public void testValidityOfAvailableRules() throws Exception { 39 37 Collection<ExtendedSourceEntry> sources = new ValidatorTagCheckerRulesPreference.TagCheckerRulesSourceEditor() 40 38 .loadAndGetAvailableSources();
Note:
See TracChangeset
for help on using the changeset viewer.