diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java index 47bf555345..a9ed4be3be 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluator.java @@ -172,11 +172,11 @@ public class PluginParameterExpressionEvaluator implements TypeAwareExpressionEv int pathSeparator = expression.indexOf('/'); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, session); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), session); + value = ReflectionValueExtractor.evaluate(expression, session); } } catch (Exception e) { // TODO don't catch exception @@ -198,7 +198,7 @@ public class PluginParameterExpressionEvaluator implements TypeAwareExpressionEv value = ReflectionValueExtractor.evaluate(pathExpression, project); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), project); + value = ReflectionValueExtractor.evaluate(expression, project); } } catch (Exception e) { // TODO don't catch exception @@ -214,11 +214,11 @@ public class PluginParameterExpressionEvaluator implements TypeAwareExpressionEv int pathSeparator = expression.indexOf('/'); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, mojoExecution); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), mojoExecution); + value = ReflectionValueExtractor.evaluate(expression, mojoExecution); } } catch (Exception e) { // TODO don't catch exception @@ -234,11 +234,11 @@ public class PluginParameterExpressionEvaluator implements TypeAwareExpressionEv PluginDescriptor pluginDescriptor = mojoDescriptor.getPluginDescriptor(); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, pluginDescriptor); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), pluginDescriptor); + value = ReflectionValueExtractor.evaluate(expression, pluginDescriptor); } } catch (Exception e) { throw new ExpressionEvaluationException( @@ -251,11 +251,11 @@ public class PluginParameterExpressionEvaluator implements TypeAwareExpressionEv int pathSeparator = expression.indexOf('/'); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, session.getSettings()); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), session.getSettings()); + value = ReflectionValueExtractor.evaluate(expression, session.getSettings()); } } catch (Exception e) { // TODO don't catch exception diff --git a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java index 56532bc051..2357af54ef 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/PluginParameterExpressionEvaluatorV4.java @@ -175,11 +175,11 @@ public class PluginParameterExpressionEvaluatorV4 implements TypeAwareExpression int pathSeparator = expression.indexOf('/'); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, session); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), session); + value = ReflectionValueExtractor.evaluate(expression, session); } } catch (Exception e) { // TODO don't catch exception @@ -206,7 +206,7 @@ public class PluginParameterExpressionEvaluatorV4 implements TypeAwareExpression value = ReflectionValueExtractor.evaluate(pathExpression, project); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), project); + value = ReflectionValueExtractor.evaluate(expression, project); } } catch (Exception e) { // TODO don't catch exception @@ -223,11 +223,11 @@ public class PluginParameterExpressionEvaluatorV4 implements TypeAwareExpression int pathSeparator = expression.indexOf('/'); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, mojoExecution); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), mojoExecution); + value = ReflectionValueExtractor.evaluate(expression, mojoExecution); } } catch (Exception e) { // TODO don't catch exception @@ -246,11 +246,11 @@ public class PluginParameterExpressionEvaluatorV4 implements TypeAwareExpression mojoExecution.getMojoDescriptor().getPluginDescriptor(); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, pluginDescriptor); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), pluginDescriptor); + value = ReflectionValueExtractor.evaluate(expression, pluginDescriptor); } } catch (Exception e) { throw new ExpressionEvaluationException( @@ -263,11 +263,11 @@ public class PluginParameterExpressionEvaluatorV4 implements TypeAwareExpression int pathSeparator = expression.indexOf('/'); if (pathSeparator > 0) { - String pathExpression = expression.substring(1, pathSeparator); + String pathExpression = expression.substring(0, pathSeparator); value = ReflectionValueExtractor.evaluate(pathExpression, session.getSettings()); value = value + expression.substring(pathSeparator); } else { - value = ReflectionValueExtractor.evaluate(expression.substring(1), session.getSettings()); + value = ReflectionValueExtractor.evaluate(expression, session.getSettings()); } } catch (Exception e) { // TODO don't catch exception diff --git a/maven-core/src/main/java/org/apache/maven/plugin/ReflectionValueExtractor.java b/maven-core/src/main/java/org/apache/maven/plugin/ReflectionValueExtractor.java index 6590ca6099..64d5453661 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/ReflectionValueExtractor.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/ReflectionValueExtractor.java @@ -18,6 +18,8 @@ */ package org.apache.maven.plugin; +import java.lang.ref.Reference; +import java.lang.ref.WeakReference; import java.lang.reflect.Array; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -41,7 +43,7 @@ class ReflectionValueExtractor { * This approach prevents permgen space overflows due to retention of discarded * classloaders. */ - private static final Map, ClassMap> CLASS_MAPS = new WeakHashMap<>(); + private static final Map, WeakReference> CLASS_MAPS = new WeakHashMap<>(); static final int EOF = -1; @@ -285,12 +287,13 @@ class ReflectionValueExtractor { } private static ClassMap getClassMap(Class clazz) { - ClassMap classMap = CLASS_MAPS.get(clazz); + Reference ref = CLASS_MAPS.get(clazz); + ClassMap classMap = ref != null ? ref.get() : null; if (classMap == null) { classMap = new ClassMap(clazz); - CLASS_MAPS.put(clazz, classMap); + CLASS_MAPS.put(clazz, new WeakReference<>(classMap)); } return classMap;