Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Vogel2015-10-07 05:56:36 +0000
committerLars Vogel2015-10-07 07:19:46 +0000
commit6a18c565bbb7d894037c554f4c3604e4f5b9f9f2 (patch)
tree29f827da25721e45aa805ca8b8e22d401f2ce623
parente86dc0b280f49c2ddf0a3311562026efc003dc6d (diff)
downloadeclipse.pde.ui-6a18c565bbb7d894037c554f4c3604e4f5b9f9f2.tar.gz
eclipse.pde.ui-6a18c565bbb7d894037c554f4c3604e4f5b9f9f2.tar.xz
eclipse.pde.ui-6a18c565bbb7d894037c554f4c3604e4f5b9f9f2.zip
Bug 479192 - Warning in PDE after moving to java 8
Change-Id: I60eb5f1ab11c4d217614eb5a0f65cec063a7ba72 Signed-off-by: Lars Vogel <Lars.Vogel@vogella.com>
-rw-r--r--ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/NLResourceHelper.java63
1 files changed, 28 insertions, 35 deletions
diff --git a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/NLResourceHelper.java b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/NLResourceHelper.java
index b477ab392e..f85ac17f65 100644
--- a/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/NLResourceHelper.java
+++ b/ui/org.eclipse.pde.core/src/org/eclipse/pde/internal/core/NLResourceHelper.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2015 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -8,6 +8,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
* EclipseSource Corporation - ongoing enhancements
+ * Lars Vogel <Lars.Vogel@vogella.com> - Bug 479192
*******************************************************************************/
package org.eclipse.pde.internal.core;
@@ -25,22 +26,12 @@ public class NLResourceHelper {
private String fNLFileBasePath;
public NLResourceHelper(String name, URL[] locations) {
- InputStream stream = null;
- try {
- stream = getResourceStream(name, locations);
+ try (InputStream stream = getResourceStream(name, locations)) {
if (stream != null) {
bundle = new PropertyResourceBundle(stream);
- stream.close();
}
} catch (IOException e) {
PDECore.logException(e);
- } finally {
- try {
- if (stream != null)
- stream.close();
- } catch (IOException e) {
- PDECore.logException(e);
- }
}
}
@@ -48,31 +39,33 @@ public class NLResourceHelper {
bundle = null;
}
- private InputStream getResourceStream(String name, URL[] locations) {
- URLClassLoader resourceLoader = new URLClassLoader(locations, null);
-
- StringTokenizer tokenizer = new StringTokenizer(Platform.getNL(), "_"); //$NON-NLS-1$
- String language = tokenizer.nextToken();
- String country = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : ""); //$NON-NLS-1$
- String variant = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : ""); //$NON-NLS-1$
-
- String suffix1 = "_" + language + "_" + country + "_" + variant; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- String suffix2 = "_" + language + "_" + country; //$NON-NLS-1$ //$NON-NLS-2$
- String suffix3 = "_" + language; //$NON-NLS-1$
- String suffix4 = ""; //$NON-NLS-1$
-
- String[] suffices = new String[] {suffix1, suffix2, suffix3, suffix4};
-
- InputStream stream = null;
- for (int i = 0; i < suffices.length; i++) {
- String candidateFileName = name + suffices[i];
- stream = resourceLoader.getResourceAsStream(candidateFileName + ".properties"); //$NON-NLS-1$
- if (stream != null) {
- fNLFileBasePath = candidateFileName;
- break;
+ private InputStream getResourceStream(String name, URL[] locations) throws IOException {
+ try (URLClassLoader resourceLoader = new URLClassLoader(locations, null)) {
+
+ StringTokenizer tokenizer = new StringTokenizer(Platform.getNL(), "_"); //$NON-NLS-1$
+ String language = tokenizer.nextToken();
+ String country = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : ""); //$NON-NLS-1$
+ String variant = (tokenizer.hasMoreTokens() ? tokenizer.nextToken() : ""); //$NON-NLS-1$
+
+ String suffix1 = "_" + language + "_" + country + "_" + variant; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ String suffix2 = "_" + language + "_" + country; //$NON-NLS-1$ //$NON-NLS-2$
+ String suffix3 = "_" + language; //$NON-NLS-1$
+ String suffix4 = ""; //$NON-NLS-1$
+
+ String[] suffices = new String[] {suffix1, suffix2, suffix3, suffix4};
+
+ InputStream stream = null;
+ for (String suffice : suffices) {
+ String candidateFileName = name + suffice;
+ stream = resourceLoader.getResourceAsStream(candidateFileName + ".properties"); //$NON-NLS-1$
+ if (stream != null) {
+ fNLFileBasePath = candidateFileName;
+ break;
+ }
}
+ return stream;
}
- return stream;
+
}
public String getResourceString(String value) {

Back to the top