freemarker-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ddek...@apache.org
Subject incubator-freemarker git commit: Initialization should fail if UnsafeMethods can't be read.
Date Thu, 16 Feb 2017 23:06:25 GMT
Repository: incubator-freemarker
Updated Branches:
  refs/heads/2.3-gae 3c0f1903a -> f188f9729


Initialization should fail if UnsafeMethods can't be read.


Project: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/commit/f188f972
Tree: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/tree/f188f972
Diff: http://git-wip-us.apache.org/repos/asf/incubator-freemarker/diff/f188f972

Branch: refs/heads/2.3-gae
Commit: f188f97296f2925fd3bf38275af483555b5bac83
Parents: 3c0f190
Author: ddekany <ddekany@apache.org>
Authored: Fri Feb 17 00:06:14 2017 +0100
Committer: ddekany <ddekany@apache.org>
Committed: Fri Feb 17 00:06:14 2017 +0100

----------------------------------------------------------------------
 .../freemarker/ext/beans/UnsafeMethods.java     | 51 ++++++++++----------
 1 file changed, 26 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-freemarker/blob/f188f972/src/main/java/freemarker/ext/beans/UnsafeMethods.java
----------------------------------------------------------------------
diff --git a/src/main/java/freemarker/ext/beans/UnsafeMethods.java b/src/main/java/freemarker/ext/beans/UnsafeMethods.java
index 6d398ec..5ed3877 100644
--- a/src/main/java/freemarker/ext/beans/UnsafeMethods.java
+++ b/src/main/java/freemarker/ext/beans/UnsafeMethods.java
@@ -21,7 +21,6 @@ package freemarker.ext.beans;
 
 import java.io.InputStream;
 import java.lang.reflect.Method;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -34,6 +33,7 @@ import freemarker.template.utility.ClassUtil;
 
 class UnsafeMethods {
 
+    private static final String UNSAFE_METHODS_PROPERTIES = "unsafeMethods.properties";
     private static final Set UNSAFE_METHODS = createUnsafeMethodsSet();
     
     private UnsafeMethods() { }
@@ -45,36 +45,37 @@ class UnsafeMethods {
     private static final Set createUnsafeMethodsSet() {
         Properties props = new Properties();
         InputStream in = BeansWrapper.class.getResourceAsStream("unsafeMethods.properties");
-        if (in != null) {
-            String methodSpec = null;
+        if (in == null) {
+            throw new IllegalStateException("Class loader resource not found: "
+                        + BeansWrapper.class.getPackage().getName() + UNSAFE_METHODS_PROPERTIES);
+        }
+        String methodSpec = null;
+        try {
             try {
+                props.load(in);
+            } finally {
+                in.close();
+            }
+            Set set = new HashSet(props.size() * 4 / 3, 1f);
+            Map primClasses = createPrimitiveClassesMap();
+            for (Iterator iterator = props.keySet().iterator(); iterator.hasNext(); ) {
+                methodSpec = (String) iterator.next();
                 try {
-                    props.load(in);
-                } finally {
-                    in.close();
-                }
-                Set set = new HashSet(props.size() * 4 / 3, 1f);
-                Map primClasses = createPrimitiveClassesMap();
-                for (Iterator iterator = props.keySet().iterator(); iterator.hasNext(); )
{
-                    methodSpec = (String) iterator.next();
-                    try {
-                        set.add(parseMethodSpec(methodSpec, primClasses));
-                    } catch (ClassNotFoundException e) {
-                        if (ClassIntrospector.DEVELOPMENT_MODE) {
-                            throw e;
-                        }
-                    } catch (NoSuchMethodException e) {
-                        if (ClassIntrospector.DEVELOPMENT_MODE) {
-                            throw e;
-                        }
+                    set.add(parseMethodSpec(methodSpec, primClasses));
+                } catch (ClassNotFoundException e) {
+                    if (ClassIntrospector.DEVELOPMENT_MODE) {
+                        throw e;
+                    }
+                } catch (NoSuchMethodException e) {
+                    if (ClassIntrospector.DEVELOPMENT_MODE) {
+                        throw e;
                     }
                 }
-                return set;
-            } catch (Exception e) {
-                throw new RuntimeException("Could not load unsafe method " + methodSpec +
" " + e.getClass().getName() + " " + e.getMessage());
             }
+            return set;
+        } catch (Exception e) {
+            throw new RuntimeException("Could not load unsafe method " + methodSpec + " "
+ e.getClass().getName() + " " + e.getMessage());
         }
-        return Collections.EMPTY_SET;
     }
 
     private static Method parseMethodSpec(String methodSpec, Map primClasses)


Mime
View raw message