[
https://issues.apache.org/jira/browse/KARAF-6964?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17315180#comment-17315180
]
Eric K. Sender edited comment on KARAF-6964 at 4/6/21, 3:45 PM:
----------------------------------------------------------------
I did a deep dive into this and found that the problem may or may not be
Opendaylight.
I haven't figured out why v0.13.3 suffers from this issue but the previous
version (v0.12.3) does not. Either way, here is how I overcame it. Namely, the
problem is this:
{code:java}
# bin/shell wrapper:install
Exception in thread "main" java.lang.NullPointerException
at
org.apache.karaf.shell.impl.console.standalone.Main.getJarsInJars(Main.java:157)
at
org.apache.karaf.shell.impl.console.standalone.Main.run(Main.java:137)
at org.apache.karaf.shell.impl.console.standalone.Main.run(Main.java:82)
at
org.apache.karaf.shell.impl.console.standalone.Main.main(Main.java:64)
{code}
This error comes up when a MANIFEST.MF file is not found inside of a .jar file
on the classpath.
[https://github.com/apache/karaf/blob/main/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java#L157]
So, I ran a little script to go through all the .jar files to find the one(s)
that don't have a MANIFEST.MF:
{code:java}
for file in `find /opt/opendaylight-0.13.3/system/ -name "*.jar"`; do
if ( ! unzip -l "$file" | grep -q MANIFEST.MF ); then
echo "$file"
fi
done
{code}
After running this, I found the one .JAR file that doesn't have a manifest:
opendaylight-0.13.3/system/javax/inject/javax.inject/1/javax.inject-1.jar (not
ODL related, but from javax:
[https://mvnrepository.com/artifact/javax.inject/javax.inject/1)] This jar file
exists in both 0.12.3 and 0.13.3. So, I am not sure why 0.12.3 system allows
this to pass, but all I can say is in 0.13.3, the program throws a
NullPointerException.
When I put in a blank MANIFEST.MF file into it, the error is passed.
I think the way around this is:
* Handle the null by either logging the issue
* Or offer a command line argument to bypass jars that have no MANIFEST.MF
(i.e., act as if its blank)
Either way, we shouldn't have chained calls because of null pointer issues like
this.
Something like this would at least allow the code to continue on.
{code:java}
private List<URL> getJarsInJars(List<URL> urls) throws IOException,
URISyntaxException {
List<URL> result = new ArrayList<>();
for (URL url : urls) {
try (JarFile jarFile = new JarFile(url.toURI().getPath())) {
Manifest manifest = jarFile.getManifest();
String embeddedArtifacts = manifest != null &&
manifest.getMainAttributes() != null ?
manifest.getMainAttributes().getValue(JarInJarConstants.REDIRECTED_CLASS_PATH_MANIFEST_NAME)
: null;
if (embeddedArtifacts != null) {
String[] artifacts = embeddedArtifacts.split( "," );
for ( String artifact : artifacts ) {
if (!artifact.endsWith(JarInJarConstants.JAR_EXTENSION )) {
continue;
}
result.add(new
URL(JarInJarConstants.JAR_INTERNAL_URL_PROTOCOL_WITH_COLON + artifact +
JarInJarConstants.JAR_INTERNAL_SEPARATOR));
}
} else log.warn("No manifest found in jarFile {}", url); //assuming a
logging system is available.
}
}
return result;
}
{code}
was (Author: esend7881):
I did a deep dive into this and found that the problem may or may not be
Opendaylight. I did a deep dive into this and found that the problem may or may
not be Opendaylight.
I haven't figured out why v0.13.3 suffers from this issue but the previous
version (v0.12.3) does not. Either way, here is how I overcame it. Namely, the
problem is this:
{code:java}
# bin/shell wrapper:install
Exception in thread "main" java.lang.NullPointerException
at
org.apache.karaf.shell.impl.console.standalone.Main.getJarsInJars(Main.java:157)
at
org.apache.karaf.shell.impl.console.standalone.Main.run(Main.java:137)
at org.apache.karaf.shell.impl.console.standalone.Main.run(Main.java:82)
at
org.apache.karaf.shell.impl.console.standalone.Main.main(Main.java:64)
{code}
This error comes up when a MANIFEST.MF file is not found inside of a .jar file
on the classpath.
[https://github.com/apache/karaf/blob/main/shell/core/src/main/java/org/apache/karaf/shell/impl/console/standalone/Main.java#L157]
So, I ran a little script to go through all the .jar files to find the one(s)
that don't have a MANIFEST.MF:
{code:java}
for file in `find /opt/opendaylight-0.13.3/system/ -name "*.jar"`; do
if ( ! unzip -l "$file" | grep -q MANIFEST.MF ); then
echo "$file"
fi
done
{code}
After running this, I found the one .JAR file that doesn't have a manifest:
opendaylight-0.13.3/system/javax/inject/javax.inject/1/javax.inject-1.jar (not
ODL related, but from javax:
[https://mvnrepository.com/artifact/javax.inject/javax.inject/1)] This jar file
exists in both 0.12.3 and 0.13.3. So, I am not sure why 0.12.3 system allows
this to pass, but all I can say is in 0.13.3, the program throws a
NullPointerException.
When I put in a blank MANIFEST.MF file into it, the error is passed.
I think the way around this is:
* Handle the null by either logging the issue
* Or offer a command line argument to bypass jars that have no MANIFEST.MF
(i.e., act as if its blank)
Either way, we shouldn't have chained calls because of null pointer issues like
this.
Something like this would at least allow the code to continue on.
{code:java}
private List<URL> getJarsInJars(List<URL> urls) throws IOException,
URISyntaxException {
List<URL> result = new ArrayList<>();
for (URL url : urls) {
try (JarFile jarFile = new JarFile(url.toURI().getPath())) {
Manifest manifest = jarFile.getManifest();
String embeddedArtifacts = manifest != null &&
manifest.getMainAttributes() != null ?
manifest.getMainAttributes().getValue(JarInJarConstants.REDIRECTED_CLASS_PATH_MANIFEST_NAME)
: null;
if (embeddedArtifacts != null) {
String[] artifacts = embeddedArtifacts.split( "," );
for ( String artifact : artifacts ) {
if (!artifact.endsWith(JarInJarConstants.JAR_EXTENSION )) {
continue;
}
result.add(new
URL(JarInJarConstants.JAR_INTERNAL_URL_PROTOCOL_WITH_COLON + artifact +
JarInJarConstants.JAR_INTERNAL_SEPARATOR));
}
} else log.warn("No manifest found in jarFile {}", url); //assuming a
logging system is available.
}
}
return result;
}
{code}
> Running bin/shell wrapper:install bug
> -------------------------------------
>
> Key: KARAF-6964
> URL: https://issues.apache.org/jira/browse/KARAF-6964
> Project: Karaf
> Issue Type: Bug
> Components: karaf
> Affects Versions: 4.2.9
> Environment: CentOS 7
> Java 11
> Reporter: Eric K. Sender
> Assignee: Jean-Baptiste Onofré
> Priority: Major
>
>
> I recently upgraded my Opendaylight from 0.11.0 to 0.13.1 which uses Karaf
> 4.2.9
> Part of my steps is setting up a systemd service, but when I run the install
> step as noted
> [here|https://karaf.apache.org/manual/latest/#_service_wrapper], I get this:
>
>
> {code:java}
> [root@localhost opendaylight]# bin/shell wrapper:install
> Exception in thread "main" java.lang.NullPointerException
> at
> org.apache.karaf.shell.impl.console.standalone.Main.getJarsInJars(Main.java:157)
> at
> org.apache.karaf.shell.impl.console.standalone.Main.run(Main.java:137)
> at
> org.apache.karaf.shell.impl.console.standalone.Main.run(Main.java:82)
> at
> org.apache.karaf.shell.impl.console.standalone.Main.main(Main.java:64)
> {code}
>
> The previous version of Karaf I was using, 4.2.2, did not have this issue. It
> set up my new services and all was fine.
>
> I don't necessarily think this error is related to `wrapper:install`. I think
> there is a bug in the logic of `bin\shell` or in the Java code that it calls.
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)