karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sk...@apache.org
Subject [karaf] branch master updated: [KARAF-6351] Handle package-less classes
Date Thu, 08 Aug 2019 12:00:35 GMT
This is an automated email from the ASF dual-hosted git repository.

skitt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e88594  [KARAF-6351] Handle package-less classes
     new 0a2de8e  Merge pull request #899 from skitt/karaf-6351
5e88594 is described below

commit 5e885946aebd43c01bd816b3c71a85d1602f8362
Author: Stephen Kitt <skitt@redhat.com>
AuthorDate: Fri Jul 5 11:13:05 2019 +0200

    [KARAF-6351] Handle package-less classes
    
    The classes command unconditionnally tries to extract a package name,
    which fails with classes which don't have one. This patch checks for
    the presence of "/" before attempting to use it as a delimiter.
    Classes with no package are assumed to not be exported.
    
    Signed-off-by: Stephen Kitt <skitt@redhat.com>
---
 .../main/java/org/apache/karaf/bundle/command/Classes.java | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Classes.java b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Classes.java
index c88f5d1..d4a4085 100644
--- a/bundle/core/src/main/java/org/apache/karaf/bundle/command/Classes.java
+++ b/bundle/core/src/main/java/org/apache/karaf/bundle/command/Classes.java
@@ -20,7 +20,6 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
-
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
@@ -76,16 +75,19 @@ public class Classes extends BundlesCommand {
         }
     }
 
-    private boolean isExported(String className, List<String> exports) throws Exception
{
+    private boolean isExported(String className, List<String> exports) {
         boolean exported = false;
-        String packageName = className.substring(0, className.lastIndexOf("/")).replaceAll("/",
".");
-        if(exports.contains(packageName)) {
-            exported = true;
+        int lastSlashIdx = className.lastIndexOf("/");
+        if (lastSlashIdx > -1) {
+            String packageName = className.substring(0, lastSlashIdx).replaceAll("/", ".");
+            if (exports.contains(packageName)) {
+                exported = true;
+            }
         }
         return exported;
     }
 
-    private List<String> getExports(Bundle bundle) throws Exception {
+    private List<String> getExports(Bundle bundle) {
         List<String> exports = new ArrayList<>();
         BundleRevision rev = bundle.adapt(BundleRevision.class);
         List<BundleCapability> caps = rev.getDeclaredCapabilities(BundleRevision.PACKAGE_NAMESPACE);


Mime
View raw message