jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1380350 - /jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
Date Mon, 03 Sep 2012 20:40:13 GMT
Author: pmouawad
Date: Mon Sep  3 20:40:13 2012
New Revision: 1380350

URL: http://svn.apache.org/viewvc?rev=1380350&view=rev
Log:
Avoid throwing exception when possible

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java

Modified: jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java?rev=1380350&r1=1380349&r2=1380350&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java Mon Sep  3 20:40:13 2012
@@ -535,9 +535,8 @@ public class JMeterUtils implements Unit
     public static String getLocaleString(String locale){
         // All keys in messages.properties are lowercase (historical reasons?)
         String resKey = locale.toLowerCase(java.util.Locale.ENGLISH);
-        try {
+        if(resources.containsKey(resKey)) {
             return resources.getString(resKey);
-        } catch (MissingResourceException e) {
         }
         return locale;
     }
@@ -565,11 +564,14 @@ public class JMeterUtils implements Unit
      */
     public static ImageIcon getImage(String name) {
         try {
-            return new ImageIcon(JMeterUtils.class.getClassLoader().getResource(
-                    "org/apache/jmeter/images/" + name.trim())); // $NON-NLS-1$
-        } catch (NullPointerException e) {
-            log.warn("no icon for " + name);
-            return null;
+            URL url = JMeterUtils.class.getClassLoader().getResource(
+                    "org/apache/jmeter/images/" + name.trim());
+            if(url != null) {
+                return new ImageIcon(url); // $NON-NLS-1$
+            } else {
+                log.warn("no icon for " + name);
+                return null;                
+            }
         } catch (NoClassDefFoundError e) {// Can be returned by headless hosts
             log.info("no icon for " + name + " " + e.getMessage());
             return null;
@@ -603,22 +605,23 @@ public class JMeterUtils implements Unit
         BufferedReader fileReader = null;
         try {
             String lineEnd = System.getProperty("line.separator"); // $NON-NLS-1$
-            fileReader = new BufferedReader(new InputStreamReader(JMeterUtils.class.getClassLoader()
-                    .getResourceAsStream(name)));
-            StringBuilder text = new StringBuilder();
-            String line = "NOTNULL"; // $NON-NLS-1$
-            while (line != null) {
-                line = fileReader.readLine();
-                if (line != null) {
-                    text.append(line);
-                    text.append(lineEnd);
+            InputStream is = JMeterUtils.class.getClassLoader().getResourceAsStream(name);
+            if(is != null) {
+                fileReader = new BufferedReader(new InputStreamReader(is));
+                StringBuilder text = new StringBuilder();
+                String line = "NOTNULL"; // $NON-NLS-1$
+                while (line != null) {
+                    line = fileReader.readLine();
+                    if (line != null) {
+                        text.append(line);
+                        text.append(lineEnd);
+                    }
                 }
+                // Done by finally block: fileReader.close();
+                return text.toString();
+            } else {
+                return ""; // $NON-NLS-1$                
             }
-            // Done by finally block: fileReader.close();
-            return text.toString();
-        } catch (NullPointerException e) // Cannot find file
-        {
-            return ""; // $NON-NLS-1$
         } catch (IOException e) {
             return ""; // $NON-NLS-1$
         } finally {
@@ -888,7 +891,6 @@ public class JMeterUtils implements Unit
         combo.setSelectedIndex(idx);
         // Redisplay.
         combo.updateUI();
-        return;
     }
 
     /**



Mime
View raw message