Skip to content

Commit 9d7849c

Browse files
committed
Merge branch '5.2.x'
# Conflicts: # spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java
2 parents a404bf5 + 939c76c commit 9d7849c

File tree

5 files changed

+76
-16
lines changed

5 files changed

+76
-16
lines changed

spring-expression/src/main/java/org/springframework/expression/spel/ast/MethodReference.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -348,8 +348,8 @@ public void generateCode(MethodVisitor mv, CodeFlow cf) {
348348

349349
generateCodeForArguments(mv, cf, method, this.children);
350350
mv.visitMethodInsn((isStaticMethod ? INVOKESTATIC : (method.isDefault() ? INVOKEINTERFACE : INVOKEVIRTUAL)),
351-
classDesc, method.getName(),
352-
CodeFlow.createSignatureDescriptor(method), method.getDeclaringClass().isInterface());
351+
classDesc, method.getName(), CodeFlow.createSignatureDescriptor(method),
352+
method.getDeclaringClass().isInterface());
353353
cf.pushDescriptor(this.exitTypeDescriptor);
354354

355355
if (this.originalPrimitiveExitTypeDescriptor != null) {

spring-expression/src/test/java/org/springframework/expression/spel/standard/SpelCompilerTests.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
class SpelCompilerTests {
4040

41-
@Test // gh-24357
41+
@Test // gh-24357
4242
void expressionCompilesWhenMethodComesFromPublicInterface() {
4343
SpelParserConfiguration config = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
4444
SpelExpressionParser parser = new SpelExpressionParser(config);
@@ -50,6 +50,31 @@ void expressionCompilesWhenMethodComesFromPublicInterface() {
5050
IntStream.rangeClosed(1, 5).forEach(i -> assertThat(expression.getValue(component)).isEqualTo(42));
5151
}
5252

53+
@Test // gh-25706
54+
void defaultMethodInvocation() {
55+
SpelParserConfiguration config = new SpelParserConfiguration(SpelCompilerMode.IMMEDIATE, null);
56+
SpelExpressionParser parser = new SpelExpressionParser(config);
57+
58+
StandardEvaluationContext context = new StandardEvaluationContext();
59+
Item item = new Item();
60+
context.setRootObject(item);
61+
62+
Expression expression = parser.parseExpression("#root.isEditable2()");
63+
assertThat(SpelCompiler.compile(expression)).isFalse();
64+
assertThat(expression.getValue(context)).isEqualTo(false);
65+
assertThat(SpelCompiler.compile(expression)).isTrue();
66+
SpelCompilationCoverageTests.assertIsCompiled(expression);
67+
assertThat(expression.getValue(context)).isEqualTo(false);
68+
69+
context.setVariable("user", new User());
70+
expression = parser.parseExpression("#root.isEditable(#user)");
71+
assertThat(SpelCompiler.compile(expression)).isFalse();
72+
assertThat(expression.getValue(context)).isEqualTo(true);
73+
assertThat(SpelCompiler.compile(expression)).isTrue();
74+
SpelCompilationCoverageTests.assertIsCompiled(expression);
75+
assertThat(expression.getValue(context)).isEqualTo(true);
76+
}
77+
5378

5479
static class OrderedComponent implements Ordered {
5580

@@ -114,4 +139,40 @@ default boolean isEditable2() {
114139
boolean hasSomeProperty();
115140
}
116141

142+
143+
public static class User {
144+
145+
boolean isAdmin() {
146+
return true;
147+
}
148+
}
149+
150+
151+
public static class Item implements Editable {
152+
153+
// some fields
154+
private String someField = "";
155+
156+
// some getters and setters
157+
158+
@Override
159+
public boolean hasSomeProperty() {
160+
return someField != null;
161+
}
162+
}
163+
164+
165+
public interface Editable {
166+
167+
default boolean isEditable(User user) {
168+
return user.isAdmin() && hasSomeProperty();
169+
}
170+
171+
default boolean isEditable2() {
172+
return false;
173+
}
174+
175+
boolean hasSomeProperty();
176+
}
177+
117178
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/StatementCreatorUtils.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,11 @@ public abstract class StatementCreatorUtils {
6666
* completely, i.e. to never even attempt to retrieve {@link PreparedStatement#getParameterMetaData()}
6767
* for {@link StatementCreatorUtils#setNull} calls.
6868
* <p>The default is "false", trying {@code getParameterType} calls first and falling back to
69-
* {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on well-known
70-
* behavior of common databases. Spring records JDBC drivers with non-working {@code getParameterType}
71-
* implementations and won't attempt to call that method for that driver again, always falling back.
72-
* <p>Consider switching this flag to "true" if you experience misbehavior at runtime, e.g. with
73-
* a connection pool setting back the {@link PreparedStatement} instance in case of an exception
74-
* thrown from {@code getParameterType} (as reported on JBoss AS 7).
69+
* {@link PreparedStatement#setNull} / {@link PreparedStatement#setObject} calls based on
70+
* well-known behavior of common databases.
71+
* <p>Consider switching this flag to "true" if you experience misbehavior at runtime,
72+
* e.g. with connection pool issues in case of an exception thrown from {@code getParameterType}
73+
* (as reported on JBoss AS 7) or in case of performance problems (as reported on PostgreSQL).
7574
*/
7675
public static final String IGNORE_GETPARAMETERTYPE_PROPERTY_NAME = "spring.jdbc.getParameterType.ignore";
7776

@@ -266,7 +265,7 @@ private static void setNull(PreparedStatement ps, int paramIndex, int sqlType, @
266265
}
267266
else if (databaseProductName.startsWith("DB2") ||
268267
jdbcDriverName.startsWith("jConnect") ||
269-
jdbcDriverName.startsWith("SQLServer")||
268+
jdbcDriverName.startsWith("SQLServer") ||
270269
jdbcDriverName.startsWith("Apache Derby")) {
271270
sqlTypeToUse = Types.VARCHAR;
272271
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataContext.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ protected List<SqlParameter> reconcileParameters(List<SqlParameter> parameters)
355355
logger.debug("Using declared out parameter '" + paramName +
356356
"' for function return value");
357357
}
358-
setFunctionReturnName(paramName);
358+
this.actualFunctionReturnName = paramName;
359359
returnDeclared = true;
360360
}
361361
}
@@ -393,8 +393,8 @@ protected List<SqlParameter> reconcileParameters(List<SqlParameter> parameters)
393393
"Unable to locate declared parameter for function return value - " +
394394
" add an SqlOutParameter with name '" + getFunctionReturnName() + "'");
395395
}
396-
else if (paramName != null) {
397-
setFunctionReturnName(paramName);
396+
else {
397+
this.actualFunctionReturnName = param.getName();
398398
}
399399
}
400400
else {
@@ -422,7 +422,7 @@ else if (paramName != null) {
422422
(StringUtils.hasLength(paramNameToUse) ? paramNameToUse : getFunctionReturnName());
423423
workParams.add(provider.createDefaultOutParameter(returnNameToUse, meta));
424424
if (isFunction()) {
425-
setFunctionReturnName(returnNameToUse);
425+
this.actualFunctionReturnName = returnNameToUse;
426426
outParamNames.add(returnNameToUse);
427427
}
428428
if (logger.isDebugEnabled()) {

src/docs/asciidoc/data-access.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4452,7 +4452,7 @@ While this usually works well, there is a potential for issues (for example, wit
44524452
case, which can be expensive with your JDBC driver. You should use a recent driver
44534453
version and consider setting the `spring.jdbc.getParameterType.ignore` property to `true`
44544454
(as a JVM system property or in a `spring.properties` file in the root of your classpath)
4455-
if you encounter a performance issue -- for example, as reported on Oracle 12c (SPR-16139).
4455+
if you encounter a performance issue (as reported on Oracle 12c, JBoss and PostgreSQL).
44564456
44574457
Alternatively, you might consider specifying the corresponding JDBC types explicitly,
44584458
either through a 'BatchPreparedStatementSetter' (as shown earlier), through an explicit type

0 commit comments

Comments
 (0)