Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
plugins {
id 'io.freefair.aspectj' version '8.13.1' apply false
// kotlinVersion is managed in gradle.properties
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false
id 'org.jetbrains.dokka'
id 'com.github.bjornvester.xjc' version '1.8.2' apply false
id 'com.gradleup.shadow' version "9.2.2" apply false
id 'me.champeau.jmh' version '0.7.2' apply false
id 'io.freefair.aspectj' version '8.13.1' apply false
id 'io.spring.nullability' version '0.0.8' apply false
id 'me.champeau.jmh' version '0.7.2' apply false
id 'org.jetbrains.dokka'
id 'org.jetbrains.kotlin.plugin.serialization' version "${kotlinVersion}" apply false // kotlinVersion is managed in gradle.properties
id 'org.openrewrite.rewrite' version '7.20.0' apply false
}

ext {
Expand All @@ -16,6 +16,8 @@ ext {

description = "Spring Framework"

apply from: "$rootDir/gradle/rewrite.gradle"

configure(allprojects) { project ->
apply plugin: "org.springframework.build.localdev"
group = "org.springframework"
Expand Down
24 changes: 24 additions & 0 deletions gradle/rewrite.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

project.apply plugin: 'org.openrewrite.rewrite'

rewrite {
activeRecipe('org.opensearch.openrewrite.SanityCheck')
setExportDatatables(true)
setFailOnDryRunResults(true)
}

dependencies {
rewrite(platform("org.openrewrite.recipe:rewrite-recipe-bom:3.18.0"))
rewrite("org.openrewrite.recipe:rewrite-migrate-java:3.21.1")
rewrite("org.openrewrite.recipe:rewrite-java-security:3.20.0")
rewrite("org.openrewrite.recipe:rewrite-rewrite:0.15.0")
rewrite("org.openrewrite.recipe:rewrite-static-analysis:2.21.0")
rewrite("org.openrewrite.recipe:rewrite-third-party:0.30.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ void afterAdviceIsInvokedLast(@Autowired Echo echo, @Autowired InvocationTrackin
static class Echo {

Object echo(Object obj) throws Exception {
if (obj instanceof Exception) {
throw (Exception) obj;
if (obj instanceof Exception exception) {
throw exception;
}
return obj;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ Echo echo() {
static class Echo {

Object echo(Object obj) throws Exception {
if (obj instanceof Exception) {
throw (Exception) obj;
if (obj instanceof Exception exception) {
throw exception;
}
return obj;
}
Expand Down
16 changes: 16 additions & 0 deletions rewrite.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
type: specs.openrewrite.org/v1beta/recipe
name: org.opensearch.openrewrite.SanityCheck
displayName: Apply all Java & Gradle best practices
description: Comprehensive code quality recipe combining modernization, security, and best practices.
tags:
- java
- gradle
- static-analysis
- cleanup
recipeList:
- org.openrewrite.gradle.EnableGradleBuildCache
- org.openrewrite.gradle.EnableGradleParallelExecution
- org.openrewrite.gradle.GradleBestPractices
- org.openrewrite.java.migrate.UpgradeToJava17
---
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serial;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -68,7 +69,7 @@
public class AdvisedSupport extends ProxyConfig implements Advised {

/** use serialVersionUID from Spring 2.0 for interoperability. */
private static final long serialVersionUID = 2651364800145442165L;
@Serial private static final long serialVersionUID = 2651364800145442165L;

private static final Advisor[] EMPTY_ADVISOR_ARRAY = new Advisor[0];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.framework;

import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.Proxy;

Expand Down Expand Up @@ -53,7 +54,7 @@ public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
*/
public static final DefaultAopProxyFactory INSTANCE = new DefaultAopProxyFactory();

private static final long serialVersionUID = 7930414337282325166L;
@Serial private static final long serialVersionUID = 7930414337282325166L;


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serial;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
Expand Down Expand Up @@ -70,7 +71,7 @@
final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializable {

/** use serialVersionUID from Spring 1.2 for interoperability. */
private static final long serialVersionUID = 5531744639992436476L;
@Serial private static final long serialVersionUID = 5531744639992436476L;


private static final String COROUTINES_FLOW_CLASS_NAME = "kotlinx.coroutines.flow.Flow";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.framework;

import java.io.Serial;
import java.io.Serializable;

import org.jspecify.annotations.Nullable;
Expand All @@ -33,7 +34,7 @@
public class ProxyConfig implements Serializable {

/** use serialVersionUID from Spring 1.2 for interoperability. */
private static final long serialVersionUID = -8409359707199703185L;
@Serial private static final long serialVersionUID = -8409359707199703185L;


private @Nullable Boolean proxyTargetClass;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.support;

import java.io.Serial;
import java.io.Serializable;

import org.jspecify.annotations.Nullable;
Expand Down Expand Up @@ -45,7 +46,7 @@
public class ComposablePointcut implements Pointcut, Serializable {

/** use serialVersionUID from Spring 1.2 for interoperability. */
private static final long serialVersionUID = -2743223737633663832L;
@Serial private static final long serialVersionUID = -2743223737633663832L;

@SuppressWarnings("serial")
private ClassFilter classFilter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.target;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

Expand Down Expand Up @@ -53,7 +54,7 @@
public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSource, BeanFactoryAware, Serializable {

/** use serialVersionUID from Spring 1.2.7 for interoperability. */
private static final long serialVersionUID = -4721607536018568393L;
@Serial private static final long serialVersionUID = -4721607536018568393L;


/** Logger available to subclasses. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.target;

import java.io.Serial;
import java.io.Serializable;
import java.util.Objects;

Expand All @@ -35,7 +36,7 @@
public final class EmptyTargetSource implements TargetSource, Serializable {

/** use serialVersionUID from Spring 1.2 for interoperability. */
private static final long serialVersionUID = 3680494563553489691L;
@Serial private static final long serialVersionUID = 3680494563553489691L;


//---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.target;

import java.io.Serial;
import java.io.Serializable;

import org.jspecify.annotations.Nullable;
Expand All @@ -40,7 +41,7 @@
public class HotSwappableTargetSource implements TargetSource, Serializable {

/** use serialVersionUID from Spring 1.2 for interoperability. */
private static final long serialVersionUID = 7497929212653839187L;
@Serial private static final long serialVersionUID = 7497929212653839187L;


/** The current target object. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.springframework.aop.target;

import java.io.Serial;
import java.io.Serializable;

import org.jspecify.annotations.Nullable;
Expand All @@ -40,7 +41,7 @@
public class SingletonTargetSource implements TargetSource, Serializable {

/** use serialVersionUID from Spring 1.2 for interoperability. */
private static final long serialVersionUID = 9031246629662423738L;
@Serial private static final long serialVersionUID = 9031246629662423738L;


/** Target cached and invoked using reflection. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void testManualProxyJavaWithStaticPointcut() {
TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
pointcut.setExpression("execution(* %s.TestService.*(..))".formatted(getClass().getName()));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl");
}

Expand All @@ -63,7 +63,7 @@ void testManualProxyJavaWithDynamicPointcut() {
TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", getClass().getName()));
pointcut.setExpression("@within(%s.Log)".formatted(getClass().getName()));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl");
}

Expand All @@ -72,7 +72,7 @@ void testManualProxyJavaWithDynamicPointcutAndProxyTargetClass() {
TestService target = new TestServiceImpl();
LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("@within(%s.Log)", getClass().getName()));
pointcut.setExpression("@within(%s.Log)".formatted(getClass().getName()));
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, target, "TestServiceImpl", true);
}

Expand All @@ -81,7 +81,7 @@ void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception

LogUserAdvice logAdvice = new LogUserAdvice();
AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
pointcut.setExpression("execution(* %s.TestService.*(..))".formatted(getClass().getName()));

// Test with default class loader first...
testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ public int hashCode() {

@Override
public String toString() {
return String.format("%s[name=%s, propertyType=%s, readMethod=%s, writeMethod=%s]",
return "%s[name=%s, propertyType=%s, readMethod=%s, writeMethod=%s]".formatted(
getClass().getSimpleName(), getName(), getPropertyType(), this.readMethod, this.writeMethod);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.net.URISyntaxException;
import java.nio.file.FileSystemNotFoundException;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
Expand All @@ -33,7 +32,7 @@
* Editor for {@code java.nio.file.Path}, to directly populate a Path
* property instead of using a String property as bridge.
*
* <p>Based on {@link Paths#get(URI)}'s resolution algorithm, checking
* <p>Based on {@link Path#of(URI)}'s resolution algorithm, checking
* registered NIO file system providers, including the default file system
* for "file:..." paths. Also supports Spring-style URL notation: any fully
* qualified standard URL and Spring's special "classpath:" pseudo-URL, as
Expand All @@ -44,7 +43,7 @@
* @author Juergen Hoeller
* @since 4.3.2
* @see java.nio.file.Path
* @see Paths#get(URI)
* @see Path#of(URI)
* @see ResourceEditor
* @see org.springframework.core.io.ResourceLoader
* @see FileEditor
Expand Down Expand Up @@ -83,7 +82,7 @@ public void setAsText(String text) throws IllegalArgumentException {
// No NIO candidate except for "C:" style drive letters
nioPathCandidate = (scheme.length() == 1);
// Let's try NIO file system providers via Paths.get(URI)
setValue(Paths.get(uri).normalize());
setValue(Path.of(uri).normalize());
return;
}
}
Expand All @@ -104,7 +103,7 @@ public void setAsText(String text) throws IllegalArgumentException {
setValue(null);
}
else if (nioPathCandidate && (!resource.isFile() || !resource.exists())) {
setValue(Paths.get(text).normalize());
setValue(Path.of(text).normalize());
}
else {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ void setStringPropertyWithCustomEditor() {
accessor.registerCustomEditor(String.class, "name", new PropertyEditorSupport() {
@Override
public void setValue(Object value) {
if (value instanceof String[]) {
setValue(StringUtils.arrayToDelimitedString(((String[]) value), "-"));
if (value instanceof String[] strings) {
setValue(StringUtils.arrayToDelimitedString(strings, "-"));
}
else {
super.setValue(value != null ? value : "");
Expand Down Expand Up @@ -929,8 +929,8 @@ void setPrimitiveArrayPropertyLargeMatchingWithSpecificEditor() {
accessor.registerCustomEditor(int.class, "array", new PropertyEditorSupport() {
@Override
public void setValue(Object value) {
if (value instanceof Integer) {
super.setValue((Integer) value + 1);
if (value instanceof Integer integer) {
super.setValue(integer + 1);
}
}
});
Expand All @@ -947,8 +947,8 @@ void setPrimitiveArrayPropertyLargeMatchingWithIndexSpecificEditor() {
accessor.registerCustomEditor(int.class, "array[1]", new PropertyEditorSupport() {
@Override
public void setValue(Object value) {
if (value instanceof Integer) {
super.setValue((Integer) value + 1);
if (value instanceof Integer integer) {
super.setValue(integer + 1);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ThreadLocalRandom;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand Down Expand Up @@ -84,7 +85,7 @@ private static void performSet() {

for (Iterator<?> i = p.entrySet().iterator(); i.hasNext();) {
i.next();
if (Math.random() > 0.9) {
if (ThreadLocalRandom.current().nextDouble() > 0.9) {
i.remove();
}
}
Expand Down
Loading