You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by wu...@apache.org on 2020/12/09 08:21:28 UTC
[servicecomb-java-chassis] branch master updated: [SCB-2070]when
main is default package(empty), start up will fail
This is an automated email from the ASF dual-hosted git repository.
wujimin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new 751f75d [SCB-2070]when main is default package(empty), start up will fail
751f75d is described below
commit 751f75d804e22b5a9ebd96f47caa695bde99d841
Author: liubao <bi...@qq.com>
AuthorDate: Wed Dec 9 15:51:25 2020 +0800
[SCB-2070]when main is default package(empty), start up will fail
---
.../foundation/common/utils/BeanUtils.java | 2 +-
.../src/test/java/TestNoPackageMain.java | 42 ++++++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
index 0a45452..fc7606e 100644
--- a/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
+++ b/foundations/foundation-common/src/main/java/org/apache/servicecomb/foundation/common/utils/BeanUtils.java
@@ -105,7 +105,7 @@ public final class BeanUtils {
// add main class package
for (Class<?> mainClass : new Class<?>[] {JvmUtils.findMainClass(), JvmUtils.findMainClassByStackTrace()}) {
- if (mainClass != null) {
+ if (mainClass != null && mainClass.getPackage() != null) {
String pkg = mainClass.getPackage().getName();
addItem(scanPackags, pkg);
}
diff --git a/foundations/foundation-common/src/test/java/TestNoPackageMain.java b/foundations/foundation-common/src/test/java/TestNoPackageMain.java
new file mode 100644
index 0000000..75fe878
--- /dev/null
+++ b/foundations/foundation-common/src/test/java/TestNoPackageMain.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.servicecomb.foundation.common.utils.BeanUtils;
+import org.apache.servicecomb.foundation.common.utils.JvmUtils;
+import org.junit.Assert;
+import org.junit.Test;
+
+import mockit.Expectations;
+
+public class TestNoPackageMain {
+ @Test
+ public void prepareServiceCombScanPackage_mainNoPackage() {
+ System.clearProperty(BeanUtils.SCB_SCAN_PACKAGE);
+ new Expectations(JvmUtils.class) {
+ {
+ JvmUtils.findMainClass();
+ result = TestNoPackageMain.class;
+ JvmUtils.findMainClassByStackTrace();
+ result = null;
+ }
+ };
+
+ BeanUtils.prepareServiceCombScanPackage();
+
+ Assert.assertEquals("org.apache.servicecomb", System.getProperty(BeanUtils.SCB_SCAN_PACKAGE));
+ }
+}