From 5d4c2846d962a4db32afdf8be904a8f9e5a998a1 Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 4 Jul 2023 16:43:29 +0200 Subject: [PATCH] Polishing --- .../concurrent/ConcurrentTaskScheduler.java | 4 +- .../concurrent/ReschedulingRunnable.java | 6 +-- .../concurrent/ThreadPoolTaskScheduler.java | 6 +-- .../core/io/ClassPathResource.java | 39 ++++++++++--------- .../core/io/FileSystemResource.java | 21 +++++++--- .../springframework/core/io/PathResource.java | 30 +++++++------- .../support/ServletContextResource.java | 5 ++- .../function/client/ExchangeFunction.java | 5 +-- 8 files changed, 64 insertions(+), 52 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java index 577b7e2a0002..bdaa76e33e1c 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ConcurrentTaskScheduler.java @@ -206,9 +206,9 @@ public ScheduledFuture schedule(Runnable task, Trigger trigger) { @Override public ScheduledFuture schedule(Runnable task, Date startTime) { - long initialDelay = startTime.getTime() - this.clock.millis(); + long delay = startTime.getTime() - this.clock.millis(); try { - return this.scheduledExecutor.schedule(decorateTask(task, false), initialDelay, TimeUnit.MILLISECONDS); + return this.scheduledExecutor.schedule(decorateTask(task, false), delay, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + this.scheduledExecutor + "] did not accept task: " + task, ex); diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java index ca79c80fc6db..3d2ce3f88aaa 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ReschedulingRunnable.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -78,8 +78,8 @@ public ScheduledFuture schedule() { if (this.scheduledExecutionTime == null) { return null; } - long initialDelay = this.scheduledExecutionTime.getTime() - this.triggerContext.getClock().millis(); - this.currentFuture = this.executor.schedule(this, initialDelay, TimeUnit.MILLISECONDS); + long delay = this.scheduledExecutionTime.getTime() - this.triggerContext.getClock().millis(); + this.currentFuture = this.executor.schedule(this, delay, TimeUnit.MILLISECONDS); return this; } } diff --git a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java index 946f5bcc6f22..ca9a0344ea67 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java +++ b/spring-context/src/main/java/org/springframework/scheduling/concurrent/ThreadPoolTaskScheduler.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -380,9 +380,9 @@ public ScheduledFuture schedule(Runnable task, Trigger trigger) { @Override public ScheduledFuture schedule(Runnable task, Date startTime) { ScheduledExecutorService executor = getScheduledExecutor(); - long initialDelay = startTime.getTime() - this.clock.millis(); + long delay = startTime.getTime() - this.clock.millis(); try { - return executor.schedule(errorHandlingTask(task, false), initialDelay, TimeUnit.MILLISECONDS); + return executor.schedule(errorHandlingTask(task, false), delay, TimeUnit.MILLISECONDS); } catch (RejectedExecutionException ex) { throw new TaskRejectedException("Executor [" + executor + "] did not accept task: " + task, ex); diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index f99adce06ce4..9d207a431f90 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -33,13 +33,15 @@ * *

Supports resolution as {@code java.io.File} if the class path * resource resides in the file system, but not for resources in a JAR. - * Always supports resolution as URL. + * Always supports resolution as {@code java.net.URL}. * * @author Juergen Hoeller * @author Sam Brannen * @since 28.12.2003 * @see ClassLoader#getResourceAsStream(String) + * @see ClassLoader#getResource(String) * @see Class#getResourceAsStream(String) + * @see Class#getResource(String) */ public class ClassPathResource extends AbstractFileResolvingResource { @@ -124,7 +126,7 @@ public final String getPath() { } /** - * Return the ClassLoader that this resource will be obtained from. + * Return the {@link ClassLoader} that this resource will be obtained from. */ @Nullable public final ClassLoader getClassLoader() { @@ -134,8 +136,8 @@ public final ClassLoader getClassLoader() { /** * This implementation checks for the resolution of a resource URL. - * @see java.lang.ClassLoader#getResource(String) - * @see java.lang.Class#getResource(String) + * @see ClassLoader#getResource(String) + * @see Class#getResource(String) */ @Override public boolean exists() { @@ -145,8 +147,8 @@ public boolean exists() { /** * This implementation checks for the resolution of a resource URL upfront, * then proceeding with {@link AbstractFileResolvingResource}'s length check. - * @see java.lang.ClassLoader#getResource(String) - * @see java.lang.Class#getResource(String) + * @see ClassLoader#getResource(String) + * @see Class#getResource(String) */ @Override public boolean isReadable() { @@ -179,9 +181,11 @@ else if (this.classLoader != null) { } /** - * This implementation opens an InputStream for the given class path resource. - * @see java.lang.ClassLoader#getResourceAsStream(String) - * @see java.lang.Class#getResourceAsStream(String) + * This implementation opens an {@link InputStream} for the underlying class + * path resource, if available. + * @see ClassLoader#getResourceAsStream(String) + * @see Class#getResourceAsStream(String) + * @see ClassLoader#getSystemResourceAsStream(String) */ @Override public InputStream getInputStream() throws IOException { @@ -204,8 +208,8 @@ else if (this.classLoader != null) { /** * This implementation returns a URL for the underlying class path resource, * if available. - * @see java.lang.ClassLoader#getResource(String) - * @see java.lang.Class#getResource(String) + * @see ClassLoader#getResource(String) + * @see Class#getResource(String) */ @Override public URL getURL() throws IOException { @@ -217,9 +221,9 @@ public URL getURL() throws IOException { } /** - * This implementation creates a ClassPathResource, applying the given path - * relative to the path of the underlying resource of this descriptor. - * @see org.springframework.util.StringUtils#applyRelativePath(String, String) + * This implementation creates a {@code ClassPathResource}, applying the given + * path relative to the path used to create this descriptor. + * @see StringUtils#applyRelativePath(String, String) */ @Override public Resource createRelative(String relativePath) { @@ -231,7 +235,7 @@ public Resource createRelative(String relativePath) { /** * This implementation returns the name of the file that this class path * resource refers to. - * @see org.springframework.util.StringUtils#getFilename(String) + * @see StringUtils#getFilename(String) */ @Override @Nullable @@ -277,8 +281,7 @@ public boolean equals(@Nullable Object other) { } /** - * This implementation returns the hash code of the underlying - * class path location. + * This implementation returns the hash code of the underlying class path location. */ @Override public int hashCode() { diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index feb2f9067da3..cb17bf55bb95 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 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. @@ -158,6 +158,7 @@ public final String getPath() { /** * This implementation returns whether the underlying file exists. * @see java.io.File#exists() + * @see java.nio.file.Files#exists(Path, java.nio.file.LinkOption...) */ @Override public boolean exists() { @@ -169,6 +170,8 @@ public boolean exists() { * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canRead() * @see java.io.File#isDirectory() + * @see java.nio.file.Files#isReadable(Path) + * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) */ @Override public boolean isReadable() { @@ -177,8 +180,8 @@ public boolean isReadable() { } /** - * This implementation opens a NIO file stream for the underlying file. - * @see java.io.FileInputStream + * This implementation opens an NIO file stream for the underlying file. + * @see java.nio.file.Files#newInputStream(Path, java.nio.file.OpenOption...) */ @Override public InputStream getInputStream() throws IOException { @@ -195,6 +198,8 @@ public InputStream getInputStream() throws IOException { * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canWrite() * @see java.io.File#isDirectory() + * @see java.nio.file.Files#isWritable(Path) + * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) */ @Override public boolean isWritable() { @@ -204,7 +209,7 @@ public boolean isWritable() { /** * This implementation opens a FileOutputStream for the underlying file. - * @see java.io.FileOutputStream + * @see java.nio.file.Files#newOutputStream(Path, java.nio.file.OpenOption...) */ @Override public OutputStream getOutputStream() throws IOException { @@ -214,6 +219,7 @@ public OutputStream getOutputStream() throws IOException { /** * This implementation returns a URL for the underlying file. * @see java.io.File#toURI() + * @see java.nio.file.Path#toUri() */ @Override public URL getURL() throws IOException { @@ -223,6 +229,7 @@ public URL getURL() throws IOException { /** * This implementation returns a URI for the underlying file. * @see java.io.File#toURI() + * @see java.nio.file.Path#toUri() */ @Override public URI getURI() throws IOException { @@ -324,6 +331,7 @@ public Resource createRelative(String relativePath) { /** * This implementation returns the name of the file. * @see java.io.File#getName() + * @see java.nio.file.Path#getFileName() */ @Override public String getFilename() { @@ -334,6 +342,7 @@ public String getFilename() { * This implementation returns a description that includes the absolute * path of the file. * @see java.io.File#getAbsolutePath() + * @see java.nio.file.Path#toAbsolutePath() */ @Override public String getDescription() { @@ -342,7 +351,7 @@ public String getDescription() { /** - * This implementation compares the underlying File references. + * This implementation compares the underlying file paths. */ @Override public boolean equals(@Nullable Object other) { @@ -351,7 +360,7 @@ public boolean equals(@Nullable Object other) { } /** - * This implementation returns the hash code of the underlying File reference. + * This implementation returns the hash code of the underlying file path. */ @Override public int hashCode() { diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index 6412f001a2b4..5ca0fc7c27f4 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2023 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. @@ -61,7 +61,7 @@ public class PathResource extends AbstractResource implements WritableResource { /** - * Create a new PathResource from a Path handle. + * Create a new {@code PathResource} from a {@link Path} handle. *

Note: Unlike {@link FileSystemResource}, when building relative resources * via {@link #createRelative}, the relative path will be built underneath * the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"! @@ -73,7 +73,7 @@ public PathResource(Path path) { } /** - * Create a new PathResource from a Path handle. + * Create a new {@code PathResource} from a path string. *

Note: Unlike {@link FileSystemResource}, when building relative resources * via {@link #createRelative}, the relative path will be built underneath * the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"! @@ -86,7 +86,7 @@ public PathResource(String path) { } /** - * Create a new PathResource from a Path handle. + * Create a new {@code PathResource} from a {@link URI}. *

Note: Unlike {@link FileSystemResource}, when building relative resources * via {@link #createRelative}, the relative path will be built underneath * the given root: e.g. Paths.get("C:/dir1/"), relative path "dir2" → "C:/dir1/dir2"! @@ -127,7 +127,7 @@ public boolean isReadable() { } /** - * This implementation opens a InputStream for the underlying file. + * This implementation opens an {@link InputStream} for the underlying file. * @see java.nio.file.spi.FileSystemProvider#newInputStream(Path, OpenOption...) */ @Override @@ -153,7 +153,7 @@ public boolean isWritable() { } /** - * This implementation opens a OutputStream for the underlying file. + * This implementation opens an {@link OutputStream} for the underlying file. * @see java.nio.file.spi.FileSystemProvider#newOutputStream(Path, OpenOption...) */ @Override @@ -165,7 +165,7 @@ public OutputStream getOutputStream() throws IOException { } /** - * This implementation returns a URL for the underlying file. + * This implementation returns a {@link URL} for the underlying file. * @see java.nio.file.Path#toUri() * @see java.net.URI#toURL() */ @@ -175,7 +175,7 @@ public URL getURL() throws IOException { } /** - * This implementation returns a URI for the underlying file. + * This implementation returns a {@link URI} for the underlying file. * @see java.nio.file.Path#toUri() */ @Override @@ -192,7 +192,7 @@ public boolean isFile() { } /** - * This implementation returns the underlying File reference. + * This implementation returns the underlying {@link File} reference. */ @Override public File getFile() throws IOException { @@ -207,7 +207,7 @@ public File getFile() throws IOException { } /** - * This implementation opens a Channel for the underlying file. + * This implementation opens a {@link ReadableByteChannel} for the underlying file. * @see Files#newByteChannel(Path, OpenOption...) */ @Override @@ -221,7 +221,7 @@ public ReadableByteChannel readableChannel() throws IOException { } /** - * This implementation opens a Channel for the underlying file. + * This implementation opens a {@link WritableByteChannel} for the underlying file. * @see Files#newByteChannel(Path, OpenOption...) */ @Override @@ -238,7 +238,7 @@ public long contentLength() throws IOException { } /** - * This implementation returns the underlying File's timestamp. + * This implementation returns the underlying file's timestamp. * @see java.nio.file.Files#getLastModifiedTime(Path, java.nio.file.LinkOption...) */ @Override @@ -249,7 +249,7 @@ public long lastModified() throws IOException { } /** - * This implementation creates a PathResource, applying the given path + * This implementation creates a {@link PathResource}, applying the given path * relative to the path of the underlying file of this resource descriptor. * @see java.nio.file.Path#resolve(String) */ @@ -274,7 +274,7 @@ public String getDescription() { /** - * This implementation compares the underlying Path references. + * This implementation compares the underlying {@link Path} references. */ @Override public boolean equals(@Nullable Object other) { @@ -283,7 +283,7 @@ public boolean equals(@Nullable Object other) { } /** - * This implementation returns the hash code of the underlying Path reference. + * This implementation returns the hash code of the underlying {@link Path} reference. */ @Override public int hashCode() { diff --git a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java index fff20515e3eb..c8efe40c6003 100644 --- a/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java +++ b/spring-web/src/main/java/org/springframework/web/context/support/ServletContextResource.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -57,7 +57,7 @@ public class ServletContextResource extends AbstractFileResolvingResource implem /** - * Create a new ServletContextResource. + * Create a new {@code ServletContextResource} for the given path. *

The Servlet spec requires that resource paths start with a slash, * even if many containers accept paths without leading slash too. * Consequently, the given path will be prepended with a slash if it @@ -94,6 +94,7 @@ public final String getPath() { return this.path; } + /** * This implementation checks {@code ServletContext.getResource}. * @see javax.servlet.ServletContext#getResource(String) diff --git a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunction.java b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunction.java index c5325284a64d..661310b769df 100644 --- a/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunction.java +++ b/spring-webflux/src/main/java/org/springframework/web/reactive/function/client/ExchangeFunction.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -43,12 +43,11 @@ public interface ExchangeFunction { /** * Exchange the given request for a {@link ClientResponse} promise. - * *

Note: When calling this method from an * {@link ExchangeFilterFunction} that handles the response in some way, * extra care must be taken to always consume its content or otherwise * propagate it downstream for further handling, for example by the - * {@link WebClient}. Please, see the reference documentation for more + * {@link WebClient}. Please see the reference documentation for more * details on this. * @param request the request to exchange * @return the delayed response