You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by dd...@apache.org on 2026/05/10 21:28:58 UTC
(freemarker) branch 2.3-gae updated: [FREEMARKER-234] PR adjustments
This is an automated email from the ASF dual-hosted git repository.
ddekany pushed a commit to branch 2.3-gae
in repository https://gitbox.apache.org/repos/asf/freemarker.git
The following commit(s) were added to refs/heads/2.3-gae by this push:
new 2048f7d9 [FREEMARKER-234] PR adjustments
2048f7d9 is described below
commit 2048f7d91e58794bab918de1bdff2845b0842af0
Author: ddekany <dd...@apache.org>
AuthorDate: Sun May 10 21:52:03 2026 +0200
[FREEMARKER-234] PR adjustments
---
.../java/freemarker/ext/beans/BeansWrapper.java | 4 +-
.../freemarker/ext/beans/ClassIntrospector.java | 20 ++--
.../ext/beans/ClassIntrospectorBuilder.java | 18 +--
.../java/freemarker/ext/beans/_MethodUtil.java | 127 +++++++++++----------
.../freemarker/ext/beans/BeansWrapperMiscTest.java | 26 ++++-
freemarker-manual/src/main/docgen/en_US/book.xml | 14 +--
6 files changed, 112 insertions(+), 97 deletions(-)
diff --git a/freemarker-core/src/main/java/freemarker/ext/beans/BeansWrapper.java b/freemarker-core/src/main/java/freemarker/ext/beans/BeansWrapper.java
index 2a2c1886..7520cfe1 100644
--- a/freemarker-core/src/main/java/freemarker/ext/beans/BeansWrapper.java
+++ b/freemarker-core/src/main/java/freemarker/ext/beans/BeansWrapper.java
@@ -280,9 +280,7 @@ public class BeansWrapper implements RichObjectWrapper, WriteProtectable {
* bean property, just like {@code isFoo()} methods returning primitive {@code boolean} already were. Before
* this, {@link java.beans.Introspector} (which is spec-strict) reported only primitive-{@code boolean}
* {@code isFoo()} methods as property readers, so {@code Boolean isFoo()} was accessible only as a method
- * ({@code obj.isFoo()}), even though the documented behavior claims {@code obj.foo} should work for either
- * {@code getFoo()} or {@code isFoo()}. Static {@code isFoo()} methods and {@code isFoo()} methods with any
- * other return type are still not exposed as properties.
+ * ({@code obj.isFoo()}).
* </li>
* </ul>
*
diff --git a/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospector.java b/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospector.java
index 4eb05c34..73a954e2 100644
--- a/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospector.java
+++ b/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospector.java
@@ -154,7 +154,7 @@ class ClassIntrospector {
final MethodAppearanceFineTuner methodAppearanceFineTuner;
final MethodSorter methodSorter;
final boolean treatDefaultMethodsAsBeanMembers;
- final boolean treatBooleanWrapperIsGettersAsProperties;
+ final boolean treatBooleanWrapperIsMethodsAsPropertyReaders;
final ZeroArgumentNonVoidMethodPolicy defaultZeroArgumentNonVoidMethodPolicy;
final ZeroArgumentNonVoidMethodPolicy recordZeroArgumentNonVoidMethodPolicy;
final private boolean recordAware;
@@ -199,7 +199,7 @@ class ClassIntrospector {
this.methodAppearanceFineTuner = builder.getMethodAppearanceFineTuner();
this.methodSorter = builder.getMethodSorter();
this.treatDefaultMethodsAsBeanMembers = builder.getTreatDefaultMethodsAsBeanMembers();
- this.treatBooleanWrapperIsGettersAsProperties = builder.getTreatBooleanWrapperIsGettersAsProperties();
+ this.treatBooleanWrapperIsMethodsAsPropertyReaders = builder.getTreatBooleanWrapperIsMethodsAsPropertyReaders();
this.defaultZeroArgumentNonVoidMethodPolicy = builder.getDefaultZeroArgumentNonVoidMethodPolicy();
this.recordZeroArgumentNonVoidMethodPolicy = builder.getRecordZeroArgumentNonVoidMethodPolicy();
this.recordAware = defaultZeroArgumentNonVoidMethodPolicy != recordZeroArgumentNonVoidMethodPolicy;
@@ -473,7 +473,7 @@ class ClassIntrospector {
List<PropertyDescriptor> introspectorPDs = introspectorPDsArray != null ? Arrays.asList(introspectorPDsArray)
: Collections.<PropertyDescriptor>emptyList();
- if (!treatDefaultMethodsAsBeanMembers && !treatBooleanWrapperIsGettersAsProperties) {
+ if (!treatDefaultMethodsAsBeanMembers && !treatBooleanWrapperIsMethodsAsPropertyReaders) {
// java.beans.Introspector was good enough then.
return introspectorPDs;
}
@@ -490,9 +490,9 @@ class ClassIntrospector {
// creating those and use the source objects as much as possible. Also note that we initialize this lazily.
LinkedHashMap<String, Object /*PropertyReaderMethodPair|Method|PropertyDescriptor*/> mergedPRMPs = null;
- // Collect methods that look like property readers but that java.beans.Introspector did not report as such:
- // - Java 8 default interface methods (not reported by Introspector prior to its own support)
- // - isXxx() returning Boolean wrapper (spec-wise Introspector only recognises primitive boolean here)
+ // Collect methods that look like property readers but that java.beans.Introspector doesn't report as such:
+ // - Java 8 default interface methods
+ // - isXxx() returning Boolean instead of primitive boolean (spec-wise Introspector only recognizes the last)
// (Note that java.beans.Introspector discovers non-accessible public methods, and to emulate that behavior
// here, we don't utilize the accessibleMethods Map, which we might already have at this point.)
for (Method method : clazz.getMethods()) {
@@ -500,11 +500,11 @@ class ClassIntrospector {
continue;
}
boolean isDefaultMethodCandidate = treatDefaultMethodsAsBeanMembers && method.isDefault();
- boolean isBooleanWrapperIsGetterCandidate = treatBooleanWrapperIsGettersAsProperties
+ boolean isBooleanWrapperIsReadMethodCandidate = treatBooleanWrapperIsMethodsAsPropertyReaders
&& !Modifier.isStatic(method.getModifiers())
&& method.getReturnType() == Boolean.class
&& method.getName().startsWith("is");
- if (isDefaultMethodCandidate || isBooleanWrapperIsGetterCandidate) {
+ if (isDefaultMethodCandidate || isBooleanWrapperIsReadMethodCandidate) {
Class<?>[] paramTypes = method.getParameterTypes();
if (paramTypes.length == 0
|| paramTypes.length == 1 && paramTypes[0] == int.class /* indexed property reader */) {
@@ -1154,8 +1154,8 @@ class ClassIntrospector {
return treatDefaultMethodsAsBeanMembers;
}
- boolean getTreatBooleanWrapperIsGettersAsProperties() {
- return treatBooleanWrapperIsGettersAsProperties;
+ boolean getTreatBooleanWrapperIsMethodsAsPropertyReaders() {
+ return treatBooleanWrapperIsMethodsAsPropertyReaders;
}
ZeroArgumentNonVoidMethodPolicy getDefaultZeroArgumentNonVoidMethodPolicy() {
diff --git a/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospectorBuilder.java b/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospectorBuilder.java
index ee1b478d..cfb1c192 100644
--- a/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospectorBuilder.java
+++ b/freemarker-core/src/main/java/freemarker/ext/beans/ClassIntrospectorBuilder.java
@@ -47,7 +47,7 @@ final class ClassIntrospectorBuilder implements Cloneable {
private boolean exposeFields;
private MemberAccessPolicy memberAccessPolicy;
private boolean treatDefaultMethodsAsBeanMembers;
- private boolean treatBooleanWrapperIsGettersAsProperties;
+ private boolean treatBooleanWrapperIsMethodsAsPropertyReaders;
private ZeroArgumentNonVoidMethodPolicy defaultZeroArgumentNonVoidMethodPolicy;
private ZeroArgumentNonVoidMethodPolicy recordZeroArgumentNonVoidMethodPolicy;
private MethodAppearanceFineTuner methodAppearanceFineTuner;
@@ -64,7 +64,7 @@ final class ClassIntrospectorBuilder implements Cloneable {
exposeFields = ci.exposeFields;
memberAccessPolicy = ci.memberAccessPolicy;
treatDefaultMethodsAsBeanMembers = ci.treatDefaultMethodsAsBeanMembers;
- treatBooleanWrapperIsGettersAsProperties = ci.treatBooleanWrapperIsGettersAsProperties;
+ treatBooleanWrapperIsMethodsAsPropertyReaders = ci.treatBooleanWrapperIsMethodsAsPropertyReaders;
defaultZeroArgumentNonVoidMethodPolicy = ci.defaultZeroArgumentNonVoidMethodPolicy;
recordZeroArgumentNonVoidMethodPolicy = ci.recordZeroArgumentNonVoidMethodPolicy;
methodAppearanceFineTuner = ci.methodAppearanceFineTuner;
@@ -77,7 +77,7 @@ final class ClassIntrospectorBuilder implements Cloneable {
// to some version changes that affects BeansWrapper, but not the other way around.
this.incompatibleImprovements = normalizeIncompatibleImprovementsVersion(incompatibleImprovements);
treatDefaultMethodsAsBeanMembers = incompatibleImprovements.intValue() >= _VersionInts.V_2_3_26;
- treatBooleanWrapperIsGettersAsProperties = incompatibleImprovements.intValue() >= _VersionInts.V_2_3_35;
+ treatBooleanWrapperIsMethodsAsPropertyReaders = incompatibleImprovements.intValue() >= _VersionInts.V_2_3_35;
defaultZeroArgumentNonVoidMethodPolicy = ZeroArgumentNonVoidMethodPolicy.METHOD_ONLY;
recordZeroArgumentNonVoidMethodPolicy
= incompatibleImprovements.intValue() >= _VersionInts.V_2_3_33 && _Java16.INSTANCE.isSupported()
@@ -112,7 +112,7 @@ final class ClassIntrospectorBuilder implements Cloneable {
result = prime * result + incompatibleImprovements.hashCode();
result = prime * result + (exposeFields ? 1231 : 1237);
result = prime * result + (treatDefaultMethodsAsBeanMembers ? 1231 : 1237);
- result = prime * result + (treatBooleanWrapperIsGettersAsProperties ? 1231 : 1237);
+ result = prime * result + (treatBooleanWrapperIsMethodsAsPropertyReaders ? 1231 : 1237);
result = prime * result + defaultZeroArgumentNonVoidMethodPolicy.hashCode();
result = prime * result + recordZeroArgumentNonVoidMethodPolicy.hashCode();
result = prime * result + exposureLevel;
@@ -132,7 +132,7 @@ final class ClassIntrospectorBuilder implements Cloneable {
if (!incompatibleImprovements.equals(other.incompatibleImprovements)) return false;
if (exposeFields != other.exposeFields) return false;
if (treatDefaultMethodsAsBeanMembers != other.treatDefaultMethodsAsBeanMembers) return false;
- if (treatBooleanWrapperIsGettersAsProperties != other.treatBooleanWrapperIsGettersAsProperties) return false;
+ if (treatBooleanWrapperIsMethodsAsPropertyReaders != other.treatBooleanWrapperIsMethodsAsPropertyReaders) return false;
if (defaultZeroArgumentNonVoidMethodPolicy != other.defaultZeroArgumentNonVoidMethodPolicy) return false;
if (recordZeroArgumentNonVoidMethodPolicy != other.recordZeroArgumentNonVoidMethodPolicy) return false;
if (exposureLevel != other.exposureLevel) return false;
@@ -173,12 +173,12 @@ final class ClassIntrospectorBuilder implements Cloneable {
this.treatDefaultMethodsAsBeanMembers = treatDefaultMethodsAsBeanMembers;
}
- public boolean getTreatBooleanWrapperIsGettersAsProperties() {
- return treatBooleanWrapperIsGettersAsProperties;
+ public boolean getTreatBooleanWrapperIsMethodsAsPropertyReaders() {
+ return treatBooleanWrapperIsMethodsAsPropertyReaders;
}
- public void setTreatBooleanWrapperIsGettersAsProperties(boolean treatBooleanWrapperIsGettersAsProperties) {
- this.treatBooleanWrapperIsGettersAsProperties = treatBooleanWrapperIsGettersAsProperties;
+ public void setTreatBooleanWrapperIsMethodsAsPropertyReaders(boolean treatBooleanWrapperIsMethodsAsPropertyReaders) {
+ this.treatBooleanWrapperIsMethodsAsPropertyReaders = treatBooleanWrapperIsMethodsAsPropertyReaders;
}
/**
diff --git a/freemarker-core/src/main/java/freemarker/ext/beans/_MethodUtil.java b/freemarker-core/src/main/java/freemarker/ext/beans/_MethodUtil.java
index c7c24c68..33149e64 100644
--- a/freemarker-core/src/main/java/freemarker/ext/beans/_MethodUtil.java
+++ b/freemarker-core/src/main/java/freemarker/ext/beans/_MethodUtil.java
@@ -39,10 +39,10 @@ import freemarker.template.utility.ClassUtil;
/**
* For internal use only; don't depend on this, there's no backward compatibility guarantee at all!
* This class is to work around the lack of module system in Java, i.e., so that other FreeMarker packages can
- * access things inside this package that users shouldn't.
- */
+ * access things inside this package that users shouldn't.
+ */
public final class _MethodUtil {
-
+
private _MethodUtil() {
// Not meant to be instantiated
}
@@ -50,32 +50,32 @@ public final class _MethodUtil {
/**
* Determines whether the type given as the 1st argument is convertible to the type given as the 2nd argument
* for method call argument conversion. This follows the rules of the Java reflection-based method call, except
- * that since we don't have the value here, a boxed class is never seen as convertible to a primitive type.
- *
+ * that since we don't have the value here, a boxed class is never seen as convertible to a primitive type.
+ *
* @return 0 means {@code false}, non-0 means {@code true}.
- * That is, 0 is returned less specificity or incomparable specificity, also when if
- * then method was aborted because of {@code ifHigherThan}.
- * The absolute value of the returned non-0 number symbolizes how more specific it is:
- * <ul>
- * <li>1: The two classes are identical</li>
- * <li>2: The 1st type is primitive, the 2nd type is the corresponding boxing class</li>
- * <li>3: Both classes are numerical, and one is convertible into the other with widening conversion.
- * E.g., {@code int} is convertible to {@code long} and {#code double}, hence {@code int} is more
- * specific.
- * This ignores primitive VS boxed mismatches, except that a boxed class is never seen as
- * convertible to a primitive class.</li>
- * <li>4: One class is {@code instanceof} of the other, but they aren't identical.
- * But unlike in Java, primitive numerical types are {@code instanceof} {@link Number} here.</li>
- * </ul>
+ * That is, 0 is returned less specificity or incomparable specificity, also when if
+ * then method was aborted because of {@code ifHigherThan}.
+ * The absolute value of the returned non-0 number symbolizes how more specific it is:
+ * <ul>
+ * <li>1: The two classes are identical</li>
+ * <li>2: The 1st type is primitive, the 2nd type is the corresponding boxing class</li>
+ * <li>3: Both classes are numerical, and one is convertible into the other with widening conversion.
+ * E.g., {@code int} is convertible to {@code long} and {#code double}, hence {@code int} is more
+ * specific.
+ * This ignores primitive VS boxed mismatches, except that a boxed class is never seen as
+ * convertible to a primitive class.</li>
+ * <li>4: One class is {@code instanceof} of the other, but they aren't identical.
+ * But unlike in Java, primitive numerical types are {@code instanceof} {@link Number} here.</li>
+ * </ul>
*/
public static int isMoreOrSameSpecificParameterType(final Class specific, final Class generic, boolean bugfixed,
- int ifHigherThan) {
+ int ifHigherThan) {
if (ifHigherThan >= 4) return 0;
if (generic.isAssignableFrom(specific)) {
// Identity or widening reference conversion:
return generic == specific ? 1 : 4;
} else {
- final boolean specificIsPrim = specific.isPrimitive();
+ final boolean specificIsPrim = specific.isPrimitive();
final boolean genericIsPrim = generic.isPrimitive();
if (specificIsPrim) {
if (genericIsPrim) {
@@ -83,7 +83,7 @@ public final class _MethodUtil {
return isWideningPrimitiveNumberConversion(specific, generic) ? 3 : 0;
} else { // => specificIsPrim && !genericIsPrim
if (bugfixed) {
- final Class specificAsBoxed = ClassUtil.primitiveClassToBoxingClass(specific);
+ final Class specificAsBoxed = ClassUtil.primitiveClassToBoxingClass(specific);
if (specificAsBoxed == generic) {
// A primitive class is more specific than its boxing class, because it can't store null
return 2;
@@ -117,22 +117,22 @@ public final class _MethodUtil {
private static boolean isWideningPrimitiveNumberConversion(final Class source, final Class target) {
if (target == Short.TYPE && (source == Byte.TYPE)) {
return true;
- } else if (target == Integer.TYPE &&
- (source == Short.TYPE || source == Byte.TYPE)) {
+ } else if (target == Integer.TYPE &&
+ (source == Short.TYPE || source == Byte.TYPE)) {
return true;
- } else if (target == Long.TYPE &&
- (source == Integer.TYPE || source == Short.TYPE ||
- source == Byte.TYPE)) {
+ } else if (target == Long.TYPE &&
+ (source == Integer.TYPE || source == Short.TYPE ||
+ source == Byte.TYPE)) {
return true;
- } else if (target == Float.TYPE &&
- (source == Long.TYPE || source == Integer.TYPE ||
- source == Short.TYPE || source == Byte.TYPE)) {
+ } else if (target == Float.TYPE &&
+ (source == Long.TYPE || source == Integer.TYPE ||
+ source == Short.TYPE || source == Byte.TYPE)) {
+ return true;
+ } else if (target == Double.TYPE &&
+ (source == Float.TYPE || source == Long.TYPE ||
+ source == Integer.TYPE || source == Short.TYPE ||
+ source == Byte.TYPE)) {
return true;
- } else if (target == Double.TYPE &&
- (source == Float.TYPE || source == Long.TYPE ||
- source == Integer.TYPE || source == Short.TYPE ||
- source == Byte.TYPE)) {
- return true;
} else {
return false;
}
@@ -141,22 +141,22 @@ public final class _MethodUtil {
private static boolean isWideningBoxedNumberConversion(final Class source, final Class target) {
if (target == Short.class && source == Byte.class) {
return true;
- } else if (target == Integer.class &&
- (source == Short.class || source == Byte.class)) {
+ } else if (target == Integer.class &&
+ (source == Short.class || source == Byte.class)) {
+ return true;
+ } else if (target == Long.class &&
+ (source == Integer.class || source == Short.class ||
+ source == Byte.class)) {
return true;
- } else if (target == Long.class &&
- (source == Integer.class || source == Short.class ||
- source == Byte.class)) {
+ } else if (target == Float.class &&
+ (source == Long.class || source == Integer.class ||
+ source == Short.class || source == Byte.class)) {
return true;
- } else if (target == Float.class &&
- (source == Long.class || source == Integer.class ||
- source == Short.class || source == Byte.class)) {
+ } else if (target == Double.class &&
+ (source == Float.class || source == Long.class ||
+ source == Integer.class || source == Short.class ||
+ source == Byte.class)) {
return true;
- } else if (target == Double.class &&
- (source == Float.class || source == Long.class ||
- source == Integer.class || source == Short.class ||
- source == Byte.class)) {
- return true;
} else {
return false;
}
@@ -170,7 +170,7 @@ public final class _MethodUtil {
collectAssignables(c1, c2, s);
return s;
}
-
+
private static void collectAssignables(Class c1, Class c2, Set s) {
if (c1.isAssignableFrom(c2)) {
s.add(c1);
@@ -196,7 +196,7 @@ public final class _MethodUtil {
}
public static boolean isVarargs(Member member) {
- if (member instanceof Method) {
+ if (member instanceof Method) {
return ((Method) member).isVarArgs();
}
if (member instanceof Constructor) {
@@ -212,13 +212,13 @@ public final class _MethodUtil {
if (!(member instanceof Method || member instanceof Constructor)) {
throw new IllegalArgumentException("\"member\" must be a Method or Constructor");
}
-
+
StringBuilder sb = new StringBuilder();
-
+
if ((member.getModifiers() & Modifier.STATIC) != 0) {
sb.append("static ");
}
-
+
String className = ClassUtil.getShortClassName(member.getDeclaringClass());
if (className != null) {
sb.append(className);
@@ -239,16 +239,16 @@ public final class _MethodUtil {
}
}
sb.append(')');
-
+
return sb.toString();
}
public static Object[] invocationErrorMessageStart(Member member) {
return invocationErrorMessageStart(member, member instanceof Constructor);
}
-
+
private static Object[] invocationErrorMessageStart(Object member, boolean isConstructor) {
- return new Object[] { "Java ", isConstructor ? "constructor " : "method ", new _DelayedJQuote(member) };
+ return new Object[]{"Java ", isConstructor ? "constructor " : "method ", new _DelayedJQuote(member)};
}
public static TemplateModelException newInvocationTemplateModelException(Object object, Member member, Throwable e) {
@@ -273,7 +273,7 @@ public final class _MethodUtil {
callableMemberDescriptor.isConstructor(),
e);
}
-
+
private static TemplateModelException newInvocationTemplateModelException(
Object parentObject, Object member, boolean isStatic, boolean isConstructor, Throwable e) {
while (e instanceof InvocationTargetException) {
@@ -288,15 +288,16 @@ public final class _MethodUtil {
return new _TemplateModelException(e,
invocationErrorMessageStart(member, isConstructor),
" threw an exception",
- isStatic || isConstructor ? "" : new Object[] {
- " when invoked on ", parentObject.getClass(), " object ", new _DelayedJQuote(parentObject)
+ isStatic || isConstructor ? "" : new Object[]{
+ " when invoked on ", parentObject.getClass(), " object ", new _DelayedJQuote(parentObject)
},
"; see cause exception in the Java stack trace.");
}
/**
* Extracts the JavaBeans property from a reader method name, or returns {@code null} if the method name doesn't
- * look like a reader method name.
+ * look like a reader method name. Note that starting from 2.3.35 this also supports the {@code Boolean isXxx}
+ * methods, even though the JavaBeans specification only supports {@code boolean isXxx}.
*/
public static String getBeanPropertyNameFromReaderMethodName(String name, Class<?> returnType) {
int start;
@@ -308,16 +309,16 @@ public final class _MethodUtil {
return null;
}
int ln = name.length();
-
+
if (start == ln) {
return null;
}
char c1 = name.charAt(start);
-
+
return start + 1 < ln && Character.isUpperCase(name.charAt(start + 1)) && Character.isUpperCase(c1)
? name.substring(start) // getFOOBar => "FOOBar" (not lower case) according the JavaBeans spec.
: new StringBuilder(ln - start).append(Character.toLowerCase(c1)).append(name, start + 1, ln)
- .toString();
+ .toString();
}
/**
diff --git a/freemarker-core/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java b/freemarker-core/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
index ff9f3873..9a928a60 100644
--- a/freemarker-core/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
+++ b/freemarker-core/src/test/java/freemarker/ext/beans/BeansWrapperMiscTest.java
@@ -119,11 +119,11 @@ public class BeansWrapperMiscTest {
}
@Test
- public void booleanWrapperIsGetterAsPropertyTest() throws TemplateModelException {
+ public void booleanWrapperIsMethodAsPropertyReaderTest() throws TemplateModelException {
// Pre-2.3.35 (legacy): Boolean isXxx() is NOT exposed as a property, only as a method.
{
BeansWrapper bw = new BeansWrapperBuilder(Configuration.VERSION_2_3_34).build();
- TemplateHashModel beanTM = (TemplateHashModel) bw.wrap(new BeanWithBooleanWrapperIsGetter());
+ TemplateHashModel beanTM = (TemplateHashModel) bw.wrap(new BeanWithBooleanWrapperIsMethod());
assertNull(beanTM.get("obsolete"));
assertThat(beanTM.get("isObsolete"), instanceOf(TemplateMethodModelEx.class));
}
@@ -131,7 +131,7 @@ public class BeansWrapperMiscTest {
// At 2.3.35+: Boolean isXxx() is exposed as a property (FREEMARKER-234).
{
BeansWrapper bw = new BeansWrapperBuilder(Configuration.VERSION_2_3_35).build();
- TemplateHashModel beanTM = (TemplateHashModel) bw.wrap(new BeanWithBooleanWrapperIsGetter());
+ TemplateHashModel beanTM = (TemplateHashModel) bw.wrap(new BeanWithBooleanWrapperIsMethod());
TemplateModel obsoleteTM = beanTM.get("obsolete");
assertThat(obsoleteTM, instanceOf(TemplateBooleanModel.class));
@@ -150,10 +150,18 @@ public class BeansWrapperMiscTest {
// The method form is still reachable (method exposure unchanged).
assertThat(beanTM.get("isObsolete"), instanceOf(TemplateMethodModelEx.class));
+
+ // As per JavaBeans spec, both isLand() and island() work the same, so we also allow that for Boolean:
+ assertThat(beanTM.get("land"), instanceOf(TemplateBooleanModel.class));
+ assertThat(beanTM.get("island"), instanceOf(TemplateMethodModelEx.class));
+
+ // Also works for interface default methods:
+ assertThat(beanTM.get("default"), instanceOf(TemplateBooleanModel.class));
+ assertThat(beanTM.get("isDefault"), instanceOf(TemplateMethodModelEx.class));
}
}
- public static class BeanWithBooleanWrapperIsGetter {
+ public static class BeanWithBooleanWrapperIsMethod implements BeanWithBooleanWrapperIsMethodInterface {
public Boolean isObsolete() {
return Boolean.TRUE;
}
@@ -166,11 +174,21 @@ public class BeansWrapperMiscTest {
return "not a property";
}
+ public Boolean island() {
+ return true;
+ }
+
public static Boolean isArchived() {
return Boolean.TRUE;
}
}
+ public interface BeanWithBooleanWrapperIsMethodInterface {
+ default Boolean isDefault() {
+ return true;
+ }
+ }
+
public static class BeanWithBothIndexedAndArrayProperty {
private final static String[] FOO = new String[] { "a", "b" };
diff --git a/freemarker-manual/src/main/docgen/en_US/book.xml b/freemarker-manual/src/main/docgen/en_US/book.xml
index 2a8445a5..c4318bea 100644
--- a/freemarker-manual/src/main/docgen/en_US/book.xml
+++ b/freemarker-manual/src/main/docgen/en_US/book.xml
@@ -20,7 +20,10 @@
<book conformance="docgen" version="5.0" xml:lang="en"
xmlns="http://docbook.org/ns/docbook"
xmlns:xlink="http://www.w3.org/1999/xlink"
->
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:db="http://docbook.org/ns/docbook">
<info>
<title>Apache FreeMarker Manual</title>
@@ -30609,13 +30612,8 @@ TemplateModel x = env.getVariable("x"); // get variable x</programlisting>
<literal>foo</literal> bean property, if you set the <link
linkend="pgui_config_incompatible_improvements_how_to_set"><literal>incompatible_improvements</literal>
setting</link> to 2.3.35 or higher. Earlier this only worked if
- the return type was primitive <literal>boolean</literal>, which
- contradicted the documented behavior stating that
- <literal>model.foo</literal> invokes either
- <literal>obj.getFoo()</literal> or
- <literal>obj.isFoo()</literal>. Static methods, and
- <literal>isFoo()</literal> methods with any other return type,
- are still not exposed as properties.</para>
+ the return type was primitive <literal>boolean</literal>,
+ consistently with the JavaBeans specification.</para>
</listitem>
</itemizedlist>
</section>