You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by al...@apache.org on 2022/11/02 04:57:53 UTC
[dubbo] branch 3.1 updated: use Files.newInputStream instead of new FileInputStream and null check (#10847)
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 1aa1aea43e use Files.newInputStream instead of new FileInputStream and null check (#10847)
1aa1aea43e is described below
commit 1aa1aea43e87c8d183b21351dc0cf7d87413db2d
Author: zhangzq7 <11...@users.noreply.github.com>
AuthorDate: Wed Nov 2 12:57:46 2022 +0800
use Files.newInputStream instead of new FileInputStream and null check (#10847)
---
.../org/apache/dubbo/maven/plugin/ClassFinder.java | 21 ++++++++++++---------
.../java/org/apache/dubbo/utils/ClassFinder.java | 20 +++++++++++---------
.../initializer/ConfigZookeeperInitializer.java | 7 ++++---
3 files changed, 27 insertions(+), 21 deletions(-)
diff --git a/dubbo-native-plugin/src/main/java/org/apache/dubbo/maven/plugin/ClassFinder.java b/dubbo-native-plugin/src/main/java/org/apache/dubbo/maven/plugin/ClassFinder.java
index c5c350e379..f05a20c2c8 100644
--- a/dubbo-native-plugin/src/main/java/org/apache/dubbo/maven/plugin/ClassFinder.java
+++ b/dubbo-native-plugin/src/main/java/org/apache/dubbo/maven/plugin/ClassFinder.java
@@ -56,15 +56,18 @@ public class ClassFinder {
private void findClassesByFile(String packageName, String resource, Set<String> result) {
File directory = new File(resource);
File[] listFiles = directory.listFiles();
- for (File file : listFiles) {
- if (file.isDirectory()) {
- findClassesByFile(packageName, file.getPath(), result);
- } else {
- String path = file.getPath();
- if (path.endsWith(".class")) {
- int packageIndex = path.indexOf(packageName.replace("/", File.separator));
- String classPath = path.substring(packageIndex, path.length() - 6);
- result.add(classPath.replace(File.separator, "."));
+ // null check
+ if (listFiles != null) {
+ for (File file : listFiles) {
+ if (file.isDirectory()) {
+ findClassesByFile(packageName, file.getPath(), result);
+ } else {
+ String path = file.getPath();
+ if (path.endsWith(".class")) {
+ int packageIndex = path.indexOf(packageName.replace("/", File.separator));
+ String classPath = path.substring(packageIndex, path.length() - 6);
+ result.add(classPath.replace(File.separator, "."));
+ }
}
}
}
diff --git a/dubbo-native/src/main/java/org/apache/dubbo/utils/ClassFinder.java b/dubbo-native/src/main/java/org/apache/dubbo/utils/ClassFinder.java
index c78d108be8..75ef3277e8 100644
--- a/dubbo-native/src/main/java/org/apache/dubbo/utils/ClassFinder.java
+++ b/dubbo-native/src/main/java/org/apache/dubbo/utils/ClassFinder.java
@@ -56,15 +56,17 @@ public class ClassFinder {
private void findClassesByFile(String packageName, String resource, Set<String> result) {
File directory = new File(resource);
File[] listFiles = directory.listFiles();
- for (File file : listFiles) {
- if (file.isDirectory()) {
- findClassesByFile(packageName, file.getPath(), result);
- } else {
- String path = file.getPath();
- if (path.endsWith(".class")) {
- int packageIndex = path.indexOf(packageName.replace("/", File.separator));
- String classPath = path.substring(packageIndex, path.length() - 6);
- result.add(classPath.replace(File.separator, "."));
+ if (listFiles != null) {
+ for (File file : listFiles) {
+ if (file.isDirectory()) {
+ findClassesByFile(packageName, file.getPath(), result);
+ } else {
+ String path = file.getPath();
+ if (path.endsWith(".class")) {
+ int packageIndex = path.indexOf(packageName.replace("/", File.separator));
+ String classPath = path.substring(packageIndex, path.length() - 6);
+ result.add(classPath.replace(File.separator, "."));
+ }
}
}
}
diff --git a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java
index cc50bb958a..f703f1e780 100644
--- a/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java
+++ b/dubbo-test/dubbo-test-check/src/main/java/org/apache/dubbo/test/check/registrycenter/initializer/ConfigZookeeperInitializer.java
@@ -23,7 +23,6 @@ import org.apache.dubbo.test.check.exception.DubboTestException;
import org.apache.dubbo.test.check.registrycenter.context.ZookeeperContext;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
@@ -54,7 +53,8 @@ public class ConfigZookeeperInitializer extends ZookeeperInitializer {
int availableAdminServerPort = NetUtils.getAvailablePort(adminServerPort);
Properties properties = new Properties();
try {
- properties.load(new FileInputStream(zooSample));
+ // use Files.newInputStream instead of new FileInputStream
+ properties.load(Files.newInputStream(zooSample.toPath()));
properties.setProperty("clientPort", String.valueOf(clientPort));
properties.setProperty("admin.serverPort", String.valueOf(availableAdminServerPort));
Path dataDir = Paths.get(zookeeperConf.getParent().toString(), "data");
@@ -87,7 +87,8 @@ public class ConfigZookeeperInitializer extends ZookeeperInitializer {
File log4j = Paths.get(zookeeperConf.toString(), "log4j.properties").toFile();
try {
- properties.load(new FileInputStream(log4j));
+ // use Files.newInputStream instead of new FileInputStream
+ properties.load(Files.newInputStream(log4j.toPath()));
Path logDir = Paths.get(zookeeperConf.getParent().toString(), "logs");
if (!Files.exists(logDir)) {
try {