This is an automated email from the ASF dual-hosted git repository.

albumenj pushed a commit to branch 3.1
in repository https://gitbox.apache.org/repos/asf/dubbo.git


The following commit(s) were added to refs/heads/3.1 by this push:
     new 1643bf3816 Add error code 0-3, and expose actual 'exception' of 
creating or deleting files in file cache merchanism. (#10538)
1643bf3816 is described below

commit 1643bf381690ca352749c0de1070a305ef4939e9
Author: Andy Cheung <[email protected]>
AuthorDate: Sat Sep 3 14:14:47 2022 +0800

    Add error code 0-3, and expose actual 'exception' of creating or deleting 
files in file cache merchanism. (#10538)
    
    * Expose the actual failure when creating 'cache store path' failed, and 
add error code 0-3.
    
    * Optimize javadoc, and forbids instantiation of some util classes.
    
    * Remove redundant testInaccessiblePath.
    
    * Add error code of 0-3 in getFile().
    
    * Optimize modifiers in FileCacheStoreTest.
    
    * Forbids instantiation of NetUtils, and add statement of not replacing 
fail-safe logger (or error type aware logger).
    
    * Optimize modifiers and add javadoc.
    
    * Code optimization and add javadoc.
    
    * Expose actual 'Exception' of deleting file.
---
 .../main/java/org/apache/dubbo/common/Version.java |  8 +--
 .../apache/dubbo/common/cache/FileCacheStore.java  | 22 +++++--
 .../dubbo/common/cache/FileCacheStoreFactory.java  | 56 +++++++++++++----
 .../dubbo/common/config/ConfigurationUtils.java    | 14 ++++-
 .../dubbo/common/timer/HashedWheelTimer.java       |  4 +-
 .../org/apache/dubbo/common/utils/LRUCache.java    |  6 ++
 .../org/apache/dubbo/common/utils/NetUtils.java    | 59 ++++++++++++++----
 .../common/cache/FileCacheStoreFactoryTest.java    |  8 +--
 .../dubbo/common/cache/FileCacheStoreTest.java     |  8 +--
 .../apache/dubbo/common/utils/NetUtilsTest.java    | 70 +++++++++++-----------
 .../dubbo/config/spring/ConfigCenterBean.java      |  5 +-
 .../registry/multicast/MulticastRegistryTest.java  | 28 ++++-----
 12 files changed, 192 insertions(+), 96 deletions(-)

diff --git a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
index 9d660141c4..ba78c46915 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/Version.java
@@ -79,7 +79,7 @@ public final class Version {
      *         a value greater than {@code 0} if {@code version1 > version2}
      */
     public static int compare(String version1, String version2) {
-        return Integer.compare (getIntVersion(version1), 
getIntVersion(version2));
+        return Integer.compare(getIntVersion(version1), 
getIntVersion(version2));
     }
 
     /**
@@ -89,10 +89,8 @@ public final class Version {
         if (StringUtils.isEmpty(version)) {
             return false;
         }
-        if (getIntVersion(version) >= 2070000) {
-            return true;
-        }
-        return false;
+
+        return getIntVersion(version) >= 2070000;
     }
 
     /**
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
index a8ecc80c2a..203c85e1d0 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStore.java
@@ -16,7 +16,7 @@
  */
 package org.apache.dubbo.common.cache;
 
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 import org.apache.dubbo.common.utils.CollectionUtils;
 
@@ -30,6 +30,8 @@ import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.nio.channels.FileLock;
 import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
@@ -41,7 +43,7 @@ import java.util.Map;
  * All items in local file are of human friendly format.
  */
 public class FileCacheStore {
-    private static final Logger logger = 
LoggerFactory.getLogger(FileCacheStore.class);
+    private static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(FileCacheStore.class);
 
     private String cacheFilePath;
     private File cacheFile;
@@ -123,8 +125,13 @@ public class FileCacheStore {
     }
 
     private static void deleteFile(File f) {
-        if (!f.delete()) {
-            logger.debug("Failed to delete file " + f.getAbsolutePath());
+
+        Path pathOfFile = f.toPath();
+
+        try {
+            Files.delete(pathOfFile);
+        } catch (IOException ioException) {
+            logger.debug("Failed to delete file " + f.getAbsolutePath(), 
ioException);
         }
     }
 
@@ -179,6 +186,9 @@ public class FileCacheStore {
         }
     }
 
+    /**
+     * An empty (or fallback) implementation of FileCacheStore. Used when 
cache file creation failed.
+     */
     protected static class Empty extends FileCacheStore {
 
         private Empty(String cacheFilePath) {
@@ -196,9 +206,13 @@ public class FileCacheStore {
 
         @Override
         public void refreshCache(Map<String, String> properties, String 
comment, long maxFileSize) {
+            // No-op.
         }
     }
 
+    /**
+     * A BufferedWriter which limits the length (in bytes). When limit exceed, 
this writer stops writing.
+     */
     private static class LimitedLengthBufferedWriter extends BufferedWriter {
 
         private long remainSize;
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
index f4375c7210..ca88d74652 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/cache/FileCacheStoreFactory.java
@@ -14,9 +14,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.dubbo.common.cache;
 
-import org.apache.dubbo.common.logger.Logger;
+import org.apache.dubbo.common.logger.ErrorTypeAwareLogger;
 import org.apache.dubbo.common.logger.LoggerFactory;
 
 import java.io.File;
@@ -25,6 +26,8 @@ import java.io.RandomAccessFile;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 import java.nio.channels.OverlappingFileLockException;
+import java.nio.file.Files;
+import java.nio.file.Path;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Map;
@@ -35,12 +38,20 @@ import java.util.concurrent.ConcurrentHashMap;
  * ClassLoader Level static share.
  * Prevent FileCacheStore being operated in multi-application
  */
-public class FileCacheStoreFactory {
-    private final static Logger logger = 
LoggerFactory.getLogger(FileCacheStoreFactory.class);
+public final class FileCacheStoreFactory {
+
+    /**
+     * Forbids instantiation.
+     */
+    private FileCacheStoreFactory() {
+        throw new UnsupportedOperationException("No instance of 
'FileCacheStoreFactory' for you! ");
+    }
+
+    private static final ErrorTypeAwareLogger logger = 
LoggerFactory.getErrorTypeAwareLogger(FileCacheStoreFactory.class);
     private static final Map<String, FileCacheStore> cacheMap = new 
ConcurrentHashMap<>();
 
     private static final String SUFFIX = ".dubbo.cache";
-    private static final char ESCAPE = '%';
+    private static final char ESCAPE_MARK = '%';
     private static final Set<Character> LEGAL_CHARACTERS = 
Collections.unmodifiableSet(new HashSet<Character>(){{
         // - $ . _ 0-9 a-z A-Z
         add('-');
@@ -64,6 +75,7 @@ public class FileCacheStoreFactory {
 
     public static FileCacheStore getInstance(String basePath, String 
cacheName, boolean enableFileCache) {
         if (basePath == null) {
+            // default case: ~/.dubbo
             basePath = System.getProperty("user.home") + File.separator + 
".dubbo";
         }
         if (basePath.endsWith(File.separator)) {
@@ -71,9 +83,20 @@ public class FileCacheStoreFactory {
         }
 
         File candidate = new File(basePath);
+        Path path = candidate.toPath();
+
         // ensure cache store path exists
-        if (!candidate.isDirectory() && !candidate.mkdirs()) {
-            throw new RuntimeException("Cache store path can't be created: " + 
candidate);
+        if (!candidate.isDirectory()) {
+            try {
+                Files.createDirectories(path);
+            } catch (IOException e) {
+                // 0-3 - cache path inaccessible
+
+                logger.error("0-3", "inaccessible of cache path", "",
+                    "Cache store path can't be created: ", e);
+
+                throw new RuntimeException("Cache store path can't be created: 
" + candidate, e);
+            }
         }
 
         cacheName = safeName(cacheName);
@@ -83,7 +106,7 @@ public class FileCacheStoreFactory {
 
         String cacheFilePath = basePath + File.separator + cacheName;
 
-        return cacheMap.computeIfAbsent(cacheFilePath, (k) -> getFile(k, 
enableFileCache));
+        return cacheMap.computeIfAbsent(cacheFilePath, k -> getFile(k, 
enableFileCache));
     }
 
     /**
@@ -100,7 +123,7 @@ public class FileCacheStoreFactory {
             if (LEGAL_CHARACTERS.contains(c)) {
                 sb.append(c);
             } else {
-                sb.append(ESCAPE);
+                sb.append(ESCAPE_MARK);
                 sb.append(String.format("%04x", (int) c));
             }
         }
@@ -114,22 +137,29 @@ public class FileCacheStoreFactory {
      * @return a file object
      */
     private static FileCacheStore getFile(String name, boolean 
enableFileCache) {
-        if(!enableFileCache) {
+        if (!enableFileCache) {
             return FileCacheStore.Empty.getInstance(name);
         }
+
         try {
             FileCacheStore.Builder builder = FileCacheStore.newBuilder();
             tryFileLock(builder, name);
             File file = new File(name);
+
             if (!file.exists()) {
-                file.createNewFile();
+                Path pathObjectOfFile = file.toPath();
+                Files.createFile(pathObjectOfFile);
             }
 
             builder.cacheFilePath(name)
                 .cacheFile(file);
+
             return builder.build();
         } catch (Throwable t) {
-            logger.info("Failed to create file store cache. Local file cache 
will be disabled. Cache file name: " + name, t);
+
+            logger.warn("0-3", "inaccessible of cache path", "",
+                "Failed to create file store cache. Local file cache will be 
disabled. Cache file name: " + name, t);
+
             return FileCacheStore.Empty.getInstance(name);
         }
     }
@@ -159,7 +189,7 @@ public class FileCacheStoreFactory {
         builder.directoryLock(dirLock).lockFile(lockFile);
     }
 
-    protected static void removeCache(String cacheFileName) {
+    static void removeCache(String cacheFileName) {
         cacheMap.remove(cacheFileName);
     }
 
@@ -167,7 +197,7 @@ public class FileCacheStoreFactory {
      * for unit test only
      */
     @Deprecated
-    protected static Map<String, FileCacheStore> getCacheMap() {
+    static Map<String, FileCacheStore> getCacheMap() {
         return cacheMap;
     }
 
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
index acbbf364cb..ab4ee4e14d 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/config/ConfigurationUtils.java
@@ -14,6 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.dubbo.common.config;
 
 import org.apache.dubbo.common.config.configcenter.DynamicConfigurationFactory;
@@ -47,7 +48,15 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.SHUTDOWN_WAIT_SE
 /**
  * Utilities for manipulating configurations from different sources
  */
-public class ConfigurationUtils {
+public final class ConfigurationUtils {
+
+    /**
+     * Forbids instantiation.
+     */
+    private ConfigurationUtils() {
+        throw new UnsupportedOperationException("No instance of 
'ConfigurationUtils' for you! ");
+    }
+
     private static final Logger logger = 
LoggerFactory.getLogger(ConfigurationUtils.class);
     private static final List<String> securityKey;
 
@@ -75,13 +84,12 @@ public class ConfigurationUtils {
      *
      * @return
      */
-
     public static Configuration getEnvConfiguration(ScopeModel scopeModel) {
         return 
getScopeModelOrDefaultApplicationModel(scopeModel).getModelEnvironment().getEnvironmentConfiguration();
     }
 
     /**
-     * Used to get an composite property value.
+     * Used to get a composite property value.
      * <p>
      * Also see {@link Environment#getConfiguration()}
      *
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
 
b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
index 2ccf48d73d..e6cb3cb51b 100644
--- 
a/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
+++ 
b/dubbo-common/src/main/java/org/apache/dubbo/common/timer/HashedWheelTimer.java
@@ -52,14 +52,14 @@ import static 
org.apache.dubbo.common.constants.CommonConstants.OS_WIN_PREFIX;
  * You can increase or decrease the accuracy of the execution timing by
  * specifying smaller or larger tick duration in the constructor.  In most
  * network applications, I/O timeout does not need to be accurate.  Therefore,
- * the default tick duration is 100 milliseconds and you will not need to try
+ * the default tick duration is 100 milliseconds, and you will not need to try
  * different configurations in most cases.
  *
  * <h3>Ticks per Wheel (Wheel Size)</h3>
  * <p>
  * {@link HashedWheelTimer} maintains a data structure called 'wheel'.
  * To put simply, a wheel is a hash table of {@link TimerTask}s whose hash
- * function is 'dead line of the task'.  The default number of ticks per wheel
+ * function is 'deadline of the task'.  The default number of ticks per wheel
  * (i.e. the size of the wheel) is 512.  You could specify a larger value
  * if you are going to schedule a lot of timeouts.
  *
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LRUCache.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LRUCache.java
index 90e905a545..425e06491c 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LRUCache.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/LRUCache.java
@@ -20,6 +20,12 @@ import java.util.LinkedHashMap;
 import java.util.concurrent.locks.Lock;
 import java.util.concurrent.locks.ReentrantLock;
 
+/**
+ * A 'least recently used' cache based on LinkedHashMap.
+ *
+ * @param <K> key
+ * @param <V> value
+ */
 public class LRUCache<K, V> extends LinkedHashMap<K, V> {
 
     private static final long serialVersionUID = -5167631809472116969L;
diff --git 
a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java 
b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
index 389f7eb9a0..473b8366b1 100644
--- a/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
+++ b/dubbo-common/src/main/java/org/apache/dubbo/common/utils/NetUtils.java
@@ -57,11 +57,25 @@ import static 
org.apache.dubbo.common.utils.CollectionUtils.first;
 /**
  * IP and Port Helper for RPC
  */
-public class NetUtils {
+public final class NetUtils {
+
+    /**
+     * Forbids instantiation.
+     */
+    private NetUtils() {
+        throw new UnsupportedOperationException("No instance of 'NetUtils' for 
you! ");
+    }
 
     private static Logger logger;
 
     static {
+        /*
+            DO NOT replace this logger to error type aware logger (or 
fail-safe logger), since its
+            logging method calls NetUtils.getLocalHost().
+
+            According to issue #4992, getLocalHost() method will be endless 
recursively invoked when network disconnected.
+        */
+
         logger = LoggerFactory.getLogger(NetUtils.class);
         if (logger instanceof FailsafeLogger) {
             logger = ((FailsafeLogger) logger).getLogger();
@@ -96,15 +110,16 @@ public class NetUtils {
         return RND_PORT_START + 
ThreadLocalRandom.current().nextInt(RND_PORT_RANGE);
     }
 
-    public synchronized static int getAvailablePort() {
+    public static synchronized int getAvailablePort() {
         int randomPort = getRandomPort();
         return getAvailablePort(randomPort);
     }
 
-    public synchronized static int getAvailablePort(int port) {
-         if (port < MIN_PORT) {
+    public static synchronized int getAvailablePort(int port) {
+        if (port < MIN_PORT) {
             return MIN_PORT;
         }
+
         for (int i = port; i < MAX_PORT; i++) {
             if (USED_PORT.get(i)) {
                 continue;
@@ -123,8 +138,8 @@ public class NetUtils {
 
     /**
      * Check the port whether is in use in os
-     * @param port
-     * @return
+     * @param port port to check
+     * @return true if it's occupied
      */
     public static boolean isPortInUsed(int port) {
         try (ServerSocket ignored = new ServerSocket(port)) {
@@ -135,10 +150,24 @@ public class NetUtils {
         return true;
     }
 
+    /**
+     * Tells whether the port to test is an invalid port.
+     *
+     * @implNote Numeric comparison only.
+     * @param port port to test
+     * @return true if invalid
+     */
     public static boolean isInvalidPort(int port) {
         return port < MIN_PORT || port > MAX_PORT;
     }
 
+    /**
+     * Tells whether the address to test is an invalid address.
+     *
+     * @implNote Pattern matching only.
+     * @param address address to test
+     * @return true if invalid
+     */
     public static boolean isValidAddress(String address) {
         return ADDRESS_PATTERN.matcher(address).matches();
     }
@@ -228,8 +257,10 @@ public class NetUtils {
 
         InetAddress address = getLocalAddress();
         if (address != null) {
-            return HOST_ADDRESS = address.getHostAddress();
+            HOST_ADDRESS = address.getHostAddress();
+            return HOST_ADDRESS;
         }
+
         return LOCALHOST_VALUE;
     }
 
@@ -352,7 +383,7 @@ public class NetUtils {
                 try {                     
                     matched = 
networkInterfaceDisplayName.matches(trimIgnoredInterface);
                 } catch (PatternSyntaxException e) {
-                    // if trimIgnoredInterface is a invalid regular 
expression, a PatternSyntaxException will be thrown out
+                    // if trimIgnoredInterface is an invalid regular 
expression, a PatternSyntaxException will be thrown out
                     logger.warn("exception occurred: " + 
networkInterfaceDisplayName + " matches " + trimIgnoredInterface, e);
                 } finally {
                     if (matched) {
@@ -521,19 +552,24 @@ public class NetUtils {
         return sb.toString();
     }
 
+    @SuppressWarnings("deprecation")
     public static void joinMulticastGroup(MulticastSocket multicastSocket, 
InetAddress multicastAddress) throws
         IOException {
         setInterface(multicastSocket, multicastAddress instanceof 
Inet6Address);
+
+        // For the deprecation notice: the equivalent only appears in JDK 9+.
         multicastSocket.setLoopbackMode(false);
         multicastSocket.joinGroup(multicastAddress);
     }
 
+    @SuppressWarnings("deprecation")
     public static void setInterface(MulticastSocket multicastSocket, boolean 
preferIpv6) throws IOException {
         boolean interfaceSet = false;
         for (NetworkInterface networkInterface : getValidNetworkInterfaces()) {
-            Enumeration addresses = networkInterface.getInetAddresses();
+            Enumeration<InetAddress> addresses = 
networkInterface.getInetAddresses();
+
             while (addresses.hasMoreElements()) {
-                InetAddress address = (InetAddress) addresses.nextElement();
+                InetAddress address = addresses.nextElement();
                 if (preferIpv6 && address instanceof Inet6Address) {
                     try {
                         if (address.isReachable(100)) {
@@ -603,7 +639,7 @@ public class NetUtils {
             splitCharacter = SPLIT_IPV6_CHARACTER;
         }
         String[] mask = pattern.split(splitCharacter);
-        //check format of pattern
+        // check format of pattern
         checkHostPattern(pattern, mask, isIpv4);
 
         host = inetAddress.getHostAddress();
@@ -618,6 +654,7 @@ public class NetUtils {
         }
 
         String[] ipAddress = host.split(splitCharacter);
+
         for (int i = 0; i < mask.length; i++) {
             if ("*".equals(mask[i]) || mask[i].equals(ipAddress[i])) {
                 continue;
diff --git 
a/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreFactoryTest.java
 
b/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreFactoryTest.java
index b2c119ccdf..927501ffce 100644
--- 
a/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreFactoryTest.java
+++ 
b/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreFactoryTest.java
@@ -25,10 +25,10 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.file.Paths;
 
-public class FileCacheStoreFactoryTest {
+class FileCacheStoreFactoryTest {
 
     @Test
-    public void testSafeName() throws URISyntaxException {
+    void testSafeName() throws URISyntaxException {
         FileCacheStore store1 = 
FileCacheStoreFactory.getInstance(getDirectoryOfClassPath(), "../../../dubbo");
         Assertions.assertEquals(getDirectoryOfClassPath() + 
"..%002f..%002f..%002fdubbo.dubbo.cache", store1.getCacheFilePath());
         store1.destroy();
@@ -39,7 +39,7 @@ public class FileCacheStoreFactoryTest {
     }
 
     @Test
-    public void testPathIsFile() throws URISyntaxException, IOException {
+    void testPathIsFile() throws URISyntaxException, IOException {
         String basePath = getDirectoryOfClassPath();
         String filePath = basePath + File.separator + "isFile";
         new File(filePath).createNewFile();
@@ -48,7 +48,7 @@ public class FileCacheStoreFactoryTest {
     }
 
     @Test
-    public void testCacheContains() throws URISyntaxException {
+    void testCacheContains() throws URISyntaxException {
         FileCacheStore store1 = 
FileCacheStoreFactory.getInstance(getDirectoryOfClassPath(), 
"testCacheContains");
         Assertions.assertNotNull(store1.getCacheFilePath());
 
diff --git 
a/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java
 
b/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java
index 6d8bf11cf1..1c2a878e72 100644
--- 
a/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java
+++ 
b/dubbo-common/src/test/java/org/apache/dubbo/common/cache/FileCacheStoreTest.java
@@ -26,11 +26,11 @@ import java.util.Map;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
 
-public class FileCacheStoreTest {
-    FileCacheStore cacheStore;
+class FileCacheStoreTest {
+    private FileCacheStore cacheStore;
 
     @Test
-    public void testCache() throws Exception {
+    void testCache() throws Exception {
         String directoryPath = getDirectoryOfClassPath();
         String filePath = "test-cache.dubbo.cache";
         cacheStore = FileCacheStoreFactory.getInstance(directoryPath, 
filePath);
@@ -54,7 +54,7 @@ public class FileCacheStoreTest {
     }
 
     @Test
-    public void testFileSizeExceed() throws Exception {
+    void testFileSizeExceed() throws Exception {
         String directoryPath = getDirectoryOfClassPath();
         Map<String, String> newProperties = new HashMap<>();
         newProperties.put("newKey1", "newValue1");
diff --git 
a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java 
b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
index 9719191e38..79f01df758 100644
--- a/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
+++ b/dubbo-common/src/test/java/org/apache/dubbo/common/utils/NetUtilsTest.java
@@ -42,51 +42,51 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-public class NetUtilsTest {
+class NetUtilsTest {
 
     @Test
-    public void testGetRandomPort() throws Exception {
+    void testGetRandomPort() throws Exception {
         assertThat(NetUtils.getRandomPort(), greaterThanOrEqualTo(30000));
         assertThat(NetUtils.getRandomPort(), greaterThanOrEqualTo(30000));
         assertThat(NetUtils.getRandomPort(), greaterThanOrEqualTo(30000));
     }
 
     @Test
-    public void testGetAvailablePort() throws Exception {
+    void testGetAvailablePort() throws Exception {
         assertThat(NetUtils.getAvailablePort(), greaterThan(0));
         assertThat(NetUtils.getAvailablePort(12345), 
greaterThanOrEqualTo(12345));
         assertThat(NetUtils.getAvailablePort(-1), greaterThanOrEqualTo(0));
     }
 
     @Test
-    public void testValidAddress() throws Exception {
+    void testValidAddress() throws Exception {
         assertTrue(NetUtils.isValidAddress("10.20.130.230:20880"));
         assertFalse(NetUtils.isValidAddress("10.20.130.230"));
         assertFalse(NetUtils.isValidAddress("10.20.130.230:666666"));
     }
 
     @Test
-    public void testIsInvalidPort() throws Exception {
+    void testIsInvalidPort() throws Exception {
         assertTrue(NetUtils.isInvalidPort(0));
         assertTrue(NetUtils.isInvalidPort(65536));
         assertFalse(NetUtils.isInvalidPort(1024));
     }
 
     @Test
-    public void testIsLocalHost() throws Exception {
+    void testIsLocalHost() throws Exception {
         assertTrue(NetUtils.isLocalHost("localhost"));
         assertTrue(NetUtils.isLocalHost("127.1.2.3"));
         assertFalse(NetUtils.isLocalHost("128.1.2.3"));
     }
 
     @Test
-    public void testIsAnyHost() throws Exception {
+    void testIsAnyHost() throws Exception {
         assertTrue(NetUtils.isAnyHost("0.0.0.0"));
         assertFalse(NetUtils.isAnyHost("1.1.1.1"));
     }
 
     @Test
-    public void testIsInvalidLocalHost() throws Exception {
+    void testIsInvalidLocalHost() throws Exception {
         assertTrue(NetUtils.isInvalidLocalHost(null));
         assertTrue(NetUtils.isInvalidLocalHost(""));
         assertTrue(NetUtils.isInvalidLocalHost("localhost"));
@@ -97,13 +97,13 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testIsValidLocalHost() throws Exception {
+    void testIsValidLocalHost() throws Exception {
         assertTrue(NetUtils.isValidLocalHost("1.2.3.4"));
         assertTrue(NetUtils.isValidLocalHost("128.0.0.1"));
     }
 
     @Test
-    public void testGetLocalSocketAddress() throws Exception {
+    void testGetLocalSocketAddress() throws Exception {
         InetSocketAddress address = 
NetUtils.getLocalSocketAddress("localhost", 12345);
         assertTrue(address.getAddress().isAnyLocalAddress());
         assertEquals(address.getPort(), 12345);
@@ -113,7 +113,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testIsValidAddress() throws Exception {
+    void testIsValidAddress() throws Exception {
         assertFalse(NetUtils.isValidV4Address((InetAddress) null));
         InetAddress address = mock(InetAddress.class);
         when(address.isLoopbackAddress()).thenReturn(true);
@@ -133,19 +133,19 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testGetLocalHost() throws Exception {
+    void testGetLocalHost() throws Exception {
         assertNotNull(NetUtils.getLocalHost());
     }
 
     @Test
-    public void testGetLocalAddress() throws Exception {
+    void testGetLocalAddress() throws Exception {
         InetAddress address = NetUtils.getLocalAddress();
         assertNotNull(address);
         assertTrue(NetUtils.isValidLocalHost(address.getHostAddress()));
     }
 
     @Test
-    public void testFilterLocalHost() throws Exception {
+    void testFilterLocalHost() throws Exception {
         assertNull(NetUtils.filterLocalHost(null));
         assertEquals(NetUtils.filterLocalHost(""), "");
         String host = NetUtils.filterLocalHost("dubbo://127.0.0.1:8080/foo");
@@ -159,18 +159,18 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testGetHostName() throws Exception {
+    void testGetHostName() throws Exception {
         assertNotNull(NetUtils.getHostName("127.0.0.1"));
     }
 
     @Test
-    public void testGetIpByHost() throws Exception {
+    void testGetIpByHost() throws Exception {
         assertThat(NetUtils.getIpByHost("localhost"), equalTo("127.0.0.1"));
         assertThat(NetUtils.getIpByHost("dubbo.local"), 
equalTo("dubbo.local"));
     }
 
     @Test
-    public void testToAddressString() throws Exception {
+    void testToAddressString() throws Exception {
         InetAddress address = mock(InetAddress.class);
         when(address.getHostAddress()).thenReturn("dubbo");
         InetSocketAddress socketAddress = new InetSocketAddress(address, 1234);
@@ -178,7 +178,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testToAddress() throws Exception {
+    void testToAddress() throws Exception {
         InetSocketAddress address = NetUtils.toAddress("localhost:1234");
         assertThat(address.getHostName(), equalTo("localhost"));
         assertThat(address.getPort(), equalTo(1234));
@@ -188,13 +188,13 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testToURL() throws Exception {
+    void testToURL() throws Exception {
         String url = NetUtils.toURL("dubbo", "host", 1234, "foo");
         assertThat(url, equalTo("dubbo://host:1234/foo"));
     }
 
     @Test
-    public void testIsValidV6Address() {
+    void testIsValidV6Address() {
         String saved = System.getProperty("java.net.preferIPv6Addresses", 
"false");
         System.setProperty("java.net.preferIPv6Addresses", "true");
 
@@ -212,11 +212,11 @@ public class NetUtilsTest {
      * Mockito starts to support mocking final classes since 2.1.0
      * see 
https://github.com/mockito/mockito/wiki/What%27s-new-in-Mockito-2#unmockable
      * But enable it will cause other UT to fail.
-     * Therefore currently disabling this UT.
+     * Therefore, currently disabling this UT.
      */
     @Disabled
     @Test
-    public void testNormalizeV6Address() {
+    void testNormalizeV6Address() {
         Inet6Address address = mock(Inet6Address.class);
         
when(address.getHostAddress()).thenReturn("fe80:0:0:0:894:aeec:f37d:23e1%en0");
         when(address.getScopeId()).thenReturn(5);
@@ -225,7 +225,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testMatchIpRangeMatchWhenIpv4() throws UnknownHostException {
+    void testMatchIpRangeMatchWhenIpv4() throws UnknownHostException {
         assertTrue(NetUtils.matchIpRange("*.*.*.*", "192.168.1.63", 90));
         assertTrue(NetUtils.matchIpRange("192.168.1.*", "192.168.1.63", 90));
         assertTrue(NetUtils.matchIpRange("192.168.1.63", "192.168.1.63", 90));
@@ -235,7 +235,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testMatchIpRangeMatchWhenIpv6() throws UnknownHostException {
+    void testMatchIpRangeMatchWhenIpv6() throws UnknownHostException {
         assertTrue(NetUtils.matchIpRange("*.*.*.*", "192.168.1.63", 90));
         assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:*", 
"234e:0:4567::3d:ff", 90));
         assertTrue(NetUtils.matchIpRange("234e:0:4567:0:0:0:3d:ee", 
"234e:0:4567::3d:ee", 90));
@@ -248,7 +248,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testMatchIpRangeMatchWhenIpv6Exception() throws 
UnknownHostException {
+    void testMatchIpRangeMatchWhenIpv6Exception() throws UnknownHostException {
         IllegalArgumentException thrown =
             assertThrows(IllegalArgumentException.class, () ->
                 NetUtils.matchIpRange("234e:0:4567::3d:*", 
"234e:0:4567::3d:ff", 90));
@@ -265,7 +265,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testMatchIpRangeMatchWhenIpWrongException() throws 
UnknownHostException {
+    void testMatchIpRangeMatchWhenIpWrongException() throws 
UnknownHostException {
         UnknownHostException thrown =
             assertThrows(UnknownHostException.class, () ->
                 NetUtils.matchIpRange("192.168.1.63", "192.168.1.ff", 90));
@@ -273,13 +273,13 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testMatchIpMatch() throws UnknownHostException {
+    void testMatchIpMatch() throws UnknownHostException {
         assertTrue(NetUtils.matchIpExpression("192.168.1.*", "192.168.1.63", 
90));
         assertTrue(NetUtils.matchIpExpression("192.168.1.192/26", 
"192.168.1.199", 90));
     }
 
     @Test
-    public void testMatchIpv6WithIpPort() throws UnknownHostException {
+    void testMatchIpv6WithIpPort() throws UnknownHostException {
         assertTrue(NetUtils.matchIpRange("[234e:0:4567::3d:ee]", 
"234e:0:4567::3d:ee", 8090));
         assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee]", 
"234e:0:4567::3d:ee", 8090));
         assertTrue(NetUtils.matchIpRange("[234e:0:4567:0:0:0:3d:ee]:8090", 
"234e:0:4567::3d:ee", 8090));
@@ -292,7 +292,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testMatchIpv4WithIpPort() throws UnknownHostException {
+    void testMatchIpv4WithIpPort() throws UnknownHostException {
         NumberFormatException thrown =
             assertThrows(NumberFormatException.class, () -> 
NetUtils.matchIpExpression("192.168.1.192/26:90", "192.168.1.199", 90));
         assertTrue(thrown instanceof NumberFormatException);
@@ -314,25 +314,25 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testLocalHost() {
+    void testLocalHost() {
         assertEquals(NetUtils.getLocalHost(), 
NetUtils.getLocalAddress().getHostAddress());
         assertTrue(NetUtils.isValidLocalHost(NetUtils.getLocalHost()));
         assertFalse(NetUtils.isInvalidLocalHost(NetUtils.getLocalHost()));
     }
 
     @Test
-    public void testIsMulticastAddress() {
+    void testIsMulticastAddress() {
         assertTrue(NetUtils.isMulticastAddress("224.0.0.1"));
         assertFalse(NetUtils.isMulticastAddress("127.0.0.1"));
     }
 
     @Test
-    public void testFindNetworkInterface() {
+    void testFindNetworkInterface() {
         assertNotNull(NetUtils.findNetworkInterface());
     }
 
     @Test
-    public void testIgnoreAllInterfaces() {
+    void testIgnoreAllInterfaces() {
         // store the origin ignored interfaces
         String originIgnoredInterfaces = this.getIgnoredInterfaces();
         try {
@@ -346,7 +346,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testIgnoreGivenInterface() {
+    void testIgnoreGivenInterface() {
         // store the origin ignored interfaces
         String originIgnoredInterfaces = this.getIgnoredInterfaces();
         try {
@@ -365,7 +365,7 @@ public class NetUtilsTest {
     }
 
     @Test
-    public void testIgnoreGivenPrefixInterfaceName() {
+    void testIgnoreGivenPrefixInterfaceName() {
         // store the origin ignored interfaces
         String originIgnoredInterfaces = this.getIgnoredInterfaces();
         try {
diff --git 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java
 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java
index 49640ee93d..3126a88a07 100644
--- 
a/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java
+++ 
b/dubbo-config/dubbo-config-spring/src/main/java/org/apache/dubbo/config/spring/ConfigCenterBean.java
@@ -33,7 +33,10 @@ import java.util.HashMap;
 import java.util.Map;
 
 /**
- * Start from 2.7.0+, export and refer will only be executed when Spring is 
fully initialized, and each Config bean will get refreshed on the start of the 
export and refer process.
+ * Starting from 2.7.0+, export and refer will only be executed when Spring is 
fully initialized.
+ * <p>
+ * Each Config bean will get refreshed on the start of the exporting and 
referring process.
+ * <p>
  * So it's ok for this bean not to be the first Dubbo Config bean being 
initialized.
  * <p>
  */
diff --git 
a/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
 
b/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
index 0da009c4a4..fde87af605 100644
--- 
a/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
+++ 
b/dubbo-registry/dubbo-registry-multicast/src/test/java/org/apache/dubbo/registry/multicast/MulticastRegistryTest.java
@@ -39,7 +39,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-public class MulticastRegistryTest {
+class MulticastRegistryTest {
 
     private String service = "org.apache.dubbo.test.injvmServie";
     private URL registryUrl = URL.valueOf("multicast://239.239.239.239/");
@@ -50,7 +50,7 @@ public class MulticastRegistryTest {
     private MulticastRegistry registry = new MulticastRegistry(registryUrl);
 
     @BeforeEach
-    public void setUp() {
+    void setUp() {
         registry.register(serviceUrl);
     }
 
@@ -58,7 +58,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#MulticastRegistry(URL)}.
      */
     @Test
-    public void testUrlError() {
+    void testUrlError() {
         Assertions.assertThrows(UnknownHostException.class, () -> {
             try {
                 URL errorUrl = URL.valueOf("multicast://mullticast.local/");
@@ -73,7 +73,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#MulticastRegistry(URL)}.
      */
     @Test
-    public void testAnyHost() {
+    void testAnyHost() {
         Assertions.assertThrows(IllegalStateException.class, () -> {
             URL errorUrl = URL.valueOf("multicast://0.0.0.0/");
             new MulticastRegistry(errorUrl);
@@ -84,7 +84,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#MulticastRegistry(URL)}.
      */
     @Test
-    public void testGetCustomPort() {
+    void testGetCustomPort() {
         int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         URL customPortUrl = URL.valueOf("multicast://239.239.239.239:" + port);
         MulticastRegistry multicastRegistry = new 
MulticastRegistry(customPortUrl);
@@ -95,7 +95,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#getRegistered()}.
      */
     @Test
-    public void testRegister() {
+    void testRegister() {
         Set<URL> registered;
         // clear first
         registered = registry.getRegistered();
@@ -117,7 +117,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#unregister(URL)}.
      */
     @Test
-    public void testUnregister() {
+    void testUnregister() {
         Set<URL> registered;
 
         // register first
@@ -137,7 +137,7 @@ public class MulticastRegistryTest {
      * .
      */
     @Test
-    public void testSubscribe() {
+    void testSubscribe() {
         // verify listener
         final URL[] notifyUrl = new URL[1];
         for (int i = 0; i < 10; i++) {
@@ -159,7 +159,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#unsubscribe(URL, 
NotifyListener)}
      */
     @Test
-    public void testUnsubscribe() {
+    void testUnsubscribe() {
         // subscribe first
         registry.subscribe(consumerUrl, new NotifyListener() {
             @Override
@@ -186,7 +186,7 @@ public class MulticastRegistryTest {
      * Test method for {@link MulticastRegistry#isAvailable()}
      */
     @Test
-    public void testAvailability() {
+    void testAvailability() {
         int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         MulticastRegistry registry = new 
MulticastRegistry(URL.valueOf("multicast://224.5.6.8:" + port));
         assertTrue(registry.isAvailable());
@@ -196,7 +196,7 @@ public class MulticastRegistryTest {
      * Test method for {@link MulticastRegistry#destroy()}
      */
     @Test
-    public void testDestroy() {
+    void testDestroy() {
         MulticastSocket socket = registry.getMulticastSocket();
         assertFalse(socket.isClosed());
 
@@ -210,7 +210,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#MulticastRegistry(URL)}
      */
     @Test
-    public void testDefaultPort() {
+    void testDefaultPort() {
         MulticastRegistry multicastRegistry = new 
MulticastRegistry(URL.valueOf("multicast://224.5.6.7"));
         try {
             MulticastSocket multicastSocket = 
multicastRegistry.getMulticastSocket();
@@ -224,7 +224,7 @@ public class MulticastRegistryTest {
      * Test method for {@link 
org.apache.dubbo.registry.multicast.MulticastRegistry#MulticastRegistry(URL)}
      */
     @Test
-    public void testCustomedPort() {
+    void testCustomedPort() {
         int port = NetUtils.getAvailablePort(20880 + new 
Random().nextInt(10000));
         MulticastRegistry multicastRegistry = new 
MulticastRegistry(URL.valueOf("multicast://224.5.6.7:" + port));
         try {
@@ -236,7 +236,7 @@ public class MulticastRegistryTest {
     }
 
     @Test
-    public void testMulticastAddress() {
+    void testMulticastAddress() {
         InetAddress multicastAddress = null;
         MulticastSocket multicastSocket = null;
         try {

Reply via email to