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 Commit: f188f97296f2925fd3bf38275af483555b5bac83 Parents: 3c0f190 Author: ddekany <[email protected]> Authored: Fri Feb 17 00:06:14 2017 +0100 Committer: ddekany <[email protected]> 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)
