[native-image] java.lang.NullPointerException when running JGit app
I'm not sure this is a bug in graalvm or me using it improperly but when running a native app (built with graalvm-ce-1.0.0-rc9 on Linux) using JGit I'm getting a NPE which seems to come from improperly initialized classes/improperly loaded properties.
Below are the details about how to reproduce the problem, thanks for any help!
Minimal kotlin app
$ tree .
.
├── build.gradle
├── reflection.json
└── src
└── App.kt
1 directory, 3 files
$ cat build.gradle
buildscript {
ext.kotlin_version = '1.3.0'
repositories { jcenter() }
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
apply plugin: 'kotlin'
apply plugin: 'application'
sourceSets {
main.java.srcDirs += 'src/'
test.java.srcDirs += 'src/'
}
mainClassName = "demo.AppKt"
defaultTasks 'run'
repositories {
jcenter()
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile 'org.eclipse.jgit:org.eclipse.jgit:5.1.3.201810200350-r'
}
jar {
manifest {
attributes 'Main-Class': 'demo.AppKt'
}
from (configurations.compile.collect { entry -> zipTree(entry) }) {
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
}
$ cat src/App.kt
package demo
import org.eclipse.jgit.api.Git
import java.io.File
fun main(args: Array<String>) {
Git.cloneRepository()
.setURI("https://github.com/eclipse/jgit.git")
.setDirectory(File("/tmp/jgit"))
.call();
}
Building the app and running it
$ cat reflection.json
[
{
"name": "org.eclipse.jgit.internal.JGitText",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.NLS",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.GlobalBundleCache",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.TranslationBundle",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
}
]
$ gradle jar
BUILD SUCCESSFUL in 2s
3 actionable tasks: 3 executed
$ ~/bin/graalvm-ce-1.0.0-rc9/bin/native-image -cp build/libs/test.jar -H:Name=helloworld -H:Class=demo.AppKt -H:+ReportUnsupportedElementsAtRuntime --delay-class-initialization-to-runtime=org.eclipse.jgit.api.Git,org.eclipse.jgit.lib.internal.WorkQueue,org.eclipse.jgit.transport.HttpAuthMethod,org.eclipse.jgit.lib.RepositoryCache -H:ReflectionConfigurationFiles=reflection.json -H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText
Build on Server(pid: 7552, port: 38683)
[helloworld:7552] classlist: 1,243.18 ms
[helloworld:7552] (cap): 1,205.05 ms
[helloworld:7552] setup: 1,577.82 ms
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
[helloworld:7552] (typeflow): 8,600.06 ms
[helloworld:7552] (objects): 5,494.54 ms
[helloworld:7552] (features): 119.91 ms
[helloworld:7552] analysis: 14,492.87 ms
[helloworld:7552] universe: 372.12 ms
[helloworld:7552] (parse): 3,127.27 ms
[helloworld:7552] (inline): 4,080.26 ms
[helloworld:7552] (compile): 14,368.61 ms
[helloworld:7552] compile: 22,465.88 ms
[helloworld:7552] image: 1,432.88 ms
[helloworld:7552] write: 516.79 ms
[helloworld:7552] [total]: 42,152.06 ms
$ ./helloworld
Exception in thread "main" java.lang.NullPointerException
at java.text.MessageFormat.applyPattern(MessageFormat.java:436)
at java.text.MessageFormat.<init>(MessageFormat.java:362)
at java.text.MessageFormat.format(MessageFormat.java:840)
at org.eclipse.jgit.api.CloneCommand.verifyDirectories(CloneCommand.java:253)
at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:189)
at demo.AppKt.main(App.kt:10)
at com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:164)
@rabadin @cstancu : Did you guys ever figure this out? I am having the same problem, with a relatively simple java app:
Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
at
I can observe the same issue with a similar stacktrace:
Caused by: java.lang.NullPointerException
at java.text.MessageFormat.applyPattern(MessageFormat.java:449)
at java.text.MessageFormat.<init>(MessageFormat.java:371)
at java.text.MessageFormat.format(MessageFormat.java:860)
at org.eclipse.jgit.lib.Config.allValuesOf(Config.java:379)
at org.eclipse.jgit.lib.Config.getEnum(Config.java:368)
at org.eclipse.jgit.treewalk.WorkingTreeOptions.<init>(WorkingTreeOptions.java:47)
at org.eclipse.jgit.lib.Config.get(Config.java:634)
at org.eclipse.jgit.treewalk.FileTreeIterator.<init>(FileTreeIterator.java:71)
at org.eclipse.jgit.api.StatusCommand.call(StatusCommand.java:113)
at
Looking further into this, I think this might be an issue with the resource bundling (or rather the reflection configuration):
private static <T> T[] allValuesOf(T value) {
try {
return (T[]) value.getClass().getMethod("values").invoke(null); //$NON-NLS-1$
} catch (Exception err) {
String typeName = value.getClass().getName();
String msg = MessageFormat.format(
JGitText.get().enumValuesNotAvailable, typeName);
throw new IllegalArgumentException(msg, err);
}
}
It looks like IllegalArgumentException is called (line 379, errors in my stack trace) with MessageFormat.format, but either the value of JGitText.get().enumValuesNotAvailable or typeName is null, causing the NPE. Looking at the source for MessageFormat, the docblock says "NullPointerException – if pattern is null"
I did a quick test on Graal with the following code, and I can reliably reproduce the NPE:
System.out.println(MessageFormat.format(JGitText.get().enumValuesNotAvailable, "test"));
Given this, I changed the reflection config to the following:
{
"name": "org.eclipse.jgit.internal.JGitText",
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.NLS",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.GlobalBundleCache",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.TranslationBundle",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
}
Notice that I've added "allDeclaredFields": true, to NLS and org.eclipse.jgit.internal.JGitText
In the end my reflection config looks like this, and I'm getting output from my application
{
"name": "org.eclipse.jgit.internal.JGitText",
"allDeclaredFields": true,
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.NLS",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.GlobalBundleCache",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name": "org.eclipse.jgit.nls.TranslationBundle",
"allDeclaredConstructors": true,
"allPublicConstructors": true,
"allDeclaredMethods": true,
"allPublicMethods": true
},
{
"name":"org.eclipse.jgit.internal.storage.dfs.DfsText",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"methods":[
{"name":"<init>","parameterTypes":[] }
]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$AutoCRLF",
"methods":[
{"name":"values","parameterTypes":[] }
]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$CheckStat",
"methods":[
{"name":"values","parameterTypes":[] }
]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$EOL",
"methods":[
{"name":"values","parameterTypes":[] }
]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$HideDotFiles",
"methods":[
{"name":"values","parameterTypes":[] }
]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$LogRefUpdates",
"allDeclaredFields":true,
"allDeclaredMethods":true,
"allPublicMethods":true,
"methods":[
{"name":"values","parameterTypes":[] }
]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$SymLinks",
"methods":[
{"name":"values","parameterTypes":[] }
]
}
I am closing this old ticket. If this is still an issue, I think you should be able to successfully use our Tracing Agent nowadays to generate such configurations for you. https://www.graalvm.org/22.0/reference-manual/native-image/Agent/