diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java b/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java index ecaa2393b2..4f00fa68a4 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/aot/DefaultBeanRegistrationCodeFragments.java @@ -138,6 +138,7 @@ class DefaultBeanRegistrationCodeFragments extends BeanRegistrationCodeFragments return null; } + @Override public CodeBlock generateSetBeanInstanceSupplierCode( GenerationContext generationContext, BeanRegistrationCode beanRegistrationCode, CodeBlock instanceSupplierCode, diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java index 8c08e401f2..06c82db07b 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionMethodGeneratorTests.java @@ -196,7 +196,7 @@ class BeanDefinitionMethodGeneratorTests { RootBeanDefinition beanDefinition, Predicate attributeFilter) { return super.generateSetBeanDefinitionPropertiesCode(generationContext, - beanRegistrationCode, beanDefinition, name -> "a".equals(name)); + beanRegistrationCode, beanDefinition, "a"::equals); } }; diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java index f234301fa7..6966bd362d 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/aot/BeanDefinitionPropertiesCodeGeneratorTests.java @@ -371,7 +371,7 @@ class BeanDefinitionPropertiesCodeGeneratorTests { void attributesWhenSomeFiltered() { this.beanDefinition.setAttribute("a", "A"); this.beanDefinition.setAttribute("b", "B"); - Predicate attributeFilter = attribute -> "a".equals(attribute); + Predicate attributeFilter = "a"::equals; this.generator = new BeanDefinitionPropertiesCodeGenerator(this.hints, attributeFilter, this.generatedMethods, (name, value) -> null); testCompiledResult(this.beanDefinition, (actual, compiled) -> { diff --git a/spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java b/spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java index b7bc696c68..7c22251d8a 100644 --- a/spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java +++ b/spring-beans/src/test/java/org/springframework/beans/factory/support/DefaultSingletonBeanRegistryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ public class DefaultSingletonBeanRegistryTests { beanRegistry.registerSingleton("tb", tb); assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb); - TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", () -> new TestBean()); + TestBean tb2 = (TestBean) beanRegistry.getSingleton("tb2", TestBean::new); assertThat(beanRegistry.getSingleton("tb2")).isSameAs(tb2); assertThat(beanRegistry.getSingleton("tb")).isSameAs(tb); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java b/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java index a21ed46862..1886964123 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/CommonAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -214,7 +214,7 @@ public class CommonAnnotationBeanPostProcessorTests { bf.registerBeanDefinition("testBean4", tbd); bf.registerResolvableDependency(BeanFactory.class, bf); - bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory) () -> new NestedTestBean()); + bf.registerResolvableDependency(INestedTestBean.class, (ObjectFactory) NestedTestBean::new); @SuppressWarnings("deprecation") org.springframework.beans.factory.config.PropertyPlaceholderConfigurer ppc = new org.springframework.beans.factory.config.PropertyPlaceholderConfigurer(); diff --git a/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java b/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java index d7e88625aa..231b47b75b 100644 --- a/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java +++ b/spring-context/src/test/java/org/springframework/context/support/ConversionServiceFactoryBeanTests.java @@ -55,6 +55,8 @@ class ConversionServiceFactoryBeanTests { void createDefaultConversionServiceWithSupplements() { ConversionServiceFactoryBean factory = new ConversionServiceFactoryBean(); Set converters = new HashSet<>(); + // The following String -> Foo Converter cannot be implemented as a lambda + // due to type erasure of the source and target types. converters.add(new Converter() { @Override public Foo convert(String source) { diff --git a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFileAssert.java b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFileAssert.java index 8b8d165ea2..d107ea8528 100644 --- a/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFileAssert.java +++ b/spring-core-test/src/main/java/org/springframework/aot/test/generator/file/DynamicFileAssert.java @@ -49,6 +49,7 @@ public class DynamicFileAssert, F extends Dyna return this.myself; } + @Override public A isEqualTo(@Nullable Object expected) { if (expected instanceof DynamicFile) { return super.isEqualTo(expected); diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurityExpressionTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurityExpressionTests.java index 5d9798fae4..673cf18e94 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurityExpressionTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/ScenariosForSpringSecurityExpressionTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -153,11 +153,15 @@ public class ScenariosForSpringSecurityExpressionTests extends AbstractExpressio public String[] getRoles() { return new String[]{"NONE"}; } public boolean hasAnyRole(String... roles) { - if (roles == null) return true; + if (roles == null) { + return true; + } String[] myRoles = getRoles(); - for (int i = 0; i < myRoles.length; i++) { - for (int j = 0; j < roles.length; j++) { - if (myRoles[i].equals(roles[j])) return true; + for (String myRole : myRoles) { + for (String role : roles) { + if (myRole.equals(role)) { + return true; + } } } return false; diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java index 98a726eff1..e357446f48 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelCompilationCoverageTests.java @@ -1796,7 +1796,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { ((SpelExpression) expression).compileExpression(); assertThat(expression.getValue(context, Boolean.class)).isFalse(); - List ls = new ArrayList(); + List ls = new ArrayList<>(); ls.add(new String("foo")); context = new StandardEvaluationContext(ls); expression = parse("get(0) != 'foo'"); @@ -1844,7 +1844,7 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { assertThat(aa.gotComparedTo).isEqualTo(bb); - List ls = new ArrayList(); + List ls = new ArrayList<>(); ls.add(new String("foo")); StandardEvaluationContext context = new StandardEvaluationContext(ls); expression = parse("get(0) == 'foo'"); @@ -5109,29 +5109,26 @@ public class SpelCompilationCoverageTests extends AbstractExpressionTests { private String stringify(Object object) { StringBuilder s = new StringBuilder(); - if (object instanceof List) { - List ls = (List) object; - for (Object l: ls) { + if (object instanceof List list) { + for (Object l: list) { s.append(l); s.append(' '); } } - else if (object instanceof Object[]) { - Object[] os = (Object[]) object; - for (Object o: os) { + else if (object instanceof Object[] objects) { + for (Object o: objects) { s.append(o); s.append(' '); } } - else if (object instanceof int[]) { - int[] is = (int[]) object; - for (int i: is) { + else if (object instanceof int[] ints) { + for (int i: ints) { s.append(i); s.append(' '); } } else { - s.append(object.toString()); + s.append(object); } return s.toString().trim(); } diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java index b4f0168f07..f15b8fe8b3 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/SpelReproTests.java @@ -1321,20 +1321,14 @@ class SpelReproTests extends AbstractExpressionTests { assertThat(Array.get(result, 1)).isEqualTo(ABC.B); assertThat(Array.get(result, 2)).isEqualTo(ABC.C); - context.addMethodResolver(new MethodResolver() { - @Override - public MethodExecutor resolve(EvaluationContext context, Object targetObject, String name, - List argumentTypes) throws AccessException { - return (context1, target, arguments) -> { - try { - Method method = XYZ.class.getMethod("values"); - Object value = method.invoke(target, arguments); - return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value)); - } - catch (Exception ex) { - throw new AccessException(ex.getMessage(), ex); - } - }; + context.addMethodResolver((context2, targetObject, name, argumentTypes) -> (context1, target, arguments) -> { + try { + Method method = XYZ.class.getMethod("values"); + Object value = method.invoke(target, arguments); + return new TypedValue(value, new TypeDescriptor(new MethodParameter(method, -1)).narrow(value)); + } + catch (Exception ex) { + throw new AccessException(ex.getMessage(), ex); } }); diff --git a/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java b/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java index 10c4acd1c1..2e789ec51b 100644 --- a/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java +++ b/spring-expression/src/test/java/org/springframework/expression/spel/testresources/PlaceOfBirth.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2022 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ package org.springframework.expression.spel.testresources; ///CLOVER:OFF public class PlaceOfBirth { + private String city; public String Country; @@ -29,11 +30,14 @@ public class PlaceOfBirth { * country - but as it is just a test object, it is ok. */ @Override - public String toString() {return city;} + public String toString() { + return city; + } public String getCity() { return city; } + public void setCity(String s) { this.city = s; } @@ -48,11 +52,10 @@ public class PlaceOfBirth { @Override public boolean equals(Object o) { - if (!(o instanceof PlaceOfBirth)) { + if (!(o instanceof PlaceOfBirth otherPOB)) { return false; } - PlaceOfBirth oPOB = (PlaceOfBirth)o; - return (city.equals(oPOB.city)); + return (city.equals(otherPOB.city)); } @Override diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java index c17449c355..7aea0c270a 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/R2dbcTransactionManager.java @@ -209,32 +209,30 @@ public class R2dbcTransactionManager extends AbstractReactiveTransactionManager connectionMono = Mono.just(txObject.getConnectionHolder().getConnection()); } - return connectionMono.flatMap(con -> { - return prepareTransactionalConnection(con, definition, transaction) - .then(Mono.from(doBegin(definition, con))) - .doOnSuccess(v -> { - txObject.getConnectionHolder().setTransactionActive(true); - Duration timeout = determineTimeout(definition); - if (!timeout.isNegative() && !timeout.isZero()) { - txObject.getConnectionHolder().setTimeoutInMillis(timeout.toMillis()); - } - // Bind the connection holder to the thread. - if (txObject.isNewConnectionHolder()) { - synchronizationManager.bindResource(obtainConnectionFactory(), txObject.getConnectionHolder()); - } - }).thenReturn(con).onErrorResume(e -> { - if (txObject.isNewConnectionHolder()) { - return ConnectionFactoryUtils.releaseConnection(con, obtainConnectionFactory()) - .doOnTerminate(() -> txObject.setConnectionHolder(null, false)) - .then(Mono.error(e)); - } - return Mono.error(e); - }); - }).onErrorResume(e -> { - CannotCreateTransactionException ex = new CannotCreateTransactionException( - "Could not open R2DBC Connection for transaction", e); - return Mono.error(ex); - }); + return connectionMono.flatMap(con -> prepareTransactionalConnection(con, definition, transaction) + .then(Mono.from(doBegin(definition, con))) + .doOnSuccess(v -> { + txObject.getConnectionHolder().setTransactionActive(true); + Duration timeout = determineTimeout(definition); + if (!timeout.isNegative() && !timeout.isZero()) { + txObject.getConnectionHolder().setTimeoutInMillis(timeout.toMillis()); + } + // Bind the connection holder to the thread. + if (txObject.isNewConnectionHolder()) { + synchronizationManager.bindResource(obtainConnectionFactory(), txObject.getConnectionHolder()); + } + }).thenReturn(con).onErrorResume(e -> { + if (txObject.isNewConnectionHolder()) { + return ConnectionFactoryUtils.releaseConnection(con, obtainConnectionFactory()) + .doOnTerminate(() -> txObject.setConnectionHolder(null, false)) + .then(Mono.error(e)); + } + return Mono.error(e); + })).onErrorResume(e -> { + CannotCreateTransactionException ex = new CannotCreateTransactionException( + "Could not open R2DBC Connection for transaction", e); + return Mono.error(ex); + }); }).then(); }