Skip to content

Commit a74e89d

Browse files
authored
fix: [269] Fixes nullpointerexception in jdeploy init (#272)
* fix: [269] Fixes nullpointerexception in jdeploy init Fixes #269 * fixed test
1 parent 5184a71 commit a74e89d

File tree

5 files changed

+77
-2
lines changed

5 files changed

+77
-2
lines changed

cli/src/main/java/ca/weblite/jdeploy/JDeploy.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ private void init(
187187
boolean prompt,
188188
boolean generateGithubWorkflow
189189
) throws IOException {
190-
final File directory = packageJSON.getParentFile();
190+
final File directory = packageJSON.getAbsoluteFile().getParentFile();
191191
ProjectInitializer projectInitializer = DIContext.getInstance().getInstance(ProjectInitializer.class);
192192
boolean dryRun = prompt; // If prompting, then we should do dry run first
193193
ProjectInitializer.Response plan = null;
194194
try {
195195
plan = projectInitializer.decorate(
196196
new ProjectInitializer.Request(
197-
packageJSON.getParentFile().getAbsolutePath(),
197+
directory.getAbsolutePath(),
198198
null,
199199
dryRun,
200200
generateGithubWorkflow,

tests/projects/InitNPETest/test.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -e
3+
echo "Running NPE fix test for jdeploy init in $(pwd)"
4+
echo "This tests that 'jdeploy init' doesn't throw NullPointerException with relative package.json path"
5+
6+
if [ -z "$JDEPLOY" ]; then
7+
echo "JDEPLOY environment variable must be set"
8+
exit 1
9+
fi
10+
11+
# Create a clean test environment
12+
rm -f package.json
13+
rm -rf dist jdeploy-bundle
14+
15+
# Create a minimal Java project structure that jdeploy can recognize
16+
mkdir -p dist
17+
18+
# Copy an existing JAR file from another test project to avoid ZipException
19+
cp ../TextEditor2/TextEditor-1.0-SNAPSHOT.jar dist/app.jar
20+
21+
# Create a minimal pom.xml to help jdeploy detect the project
22+
cat > pom.xml << 'EOF'
23+
<?xml version="1.0" encoding="UTF-8"?>
24+
<project xmlns="http://maven.apache.org/POM/4.0.0">
25+
<modelVersion>4.0.0</modelVersion>
26+
<groupId>com.test</groupId>
27+
<artifactId>npe-test-app</artifactId>
28+
<version>1.0.0</version>
29+
<name>NPE Test App</name>
30+
<build>
31+
<finalName>app</finalName>
32+
</build>
33+
</project>
34+
EOF
35+
36+
echo "Created test project structure"
37+
echo "Running 'jdeploy init --no-prompt --no-workflow'"
38+
39+
# This is the critical test: run jdeploy init
40+
# Before the fix, this would throw:
41+
# Exception in thread "main" java.lang.RuntimeException: java.lang.NullPointerException
42+
# at ca.weblite.jdeploy.JDeploy.main(JDeploy.java:714)
43+
# Caused by: java.lang.NullPointerException
44+
# at ca.weblite.jdeploy.JDeploy.init(JDeploy.java:197)
45+
46+
java -jar "$JDEPLOY" init --no-prompt --no-workflow
47+
48+
# If we get here without an exception, the NPE fix is working
49+
echo "jdeploy init completed successfully (no NPE thrown)"
50+
51+
# Verify that package.json was created
52+
if [ ! -f "package.json" ]; then
53+
echo "ERROR: package.json was not created by jdeploy init"
54+
exit 1
55+
fi
56+
57+
echo "package.json was created successfully"
58+
59+
# Verify the package.json has expected content
60+
if ! grep -q "jdeploy" package.json; then
61+
echo "ERROR: package.json does not contain jdeploy configuration"
62+
exit 1
63+
fi
64+
65+
echo "package.json contains jdeploy configuration"
66+
67+
# Clean up
68+
rm -f package.json pom.xml
69+
rm -rf dist
70+
71+
echo "InitNPETest passed: jdeploy init works without NullPointerException"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#Hello World2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
#Hello Mac

tests/projects/test.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,6 @@ bash test.sh
2121
cd ../TextEditorBundleJRECodesignDMG
2222
bash test.sh
2323
cd ../LauncherTest1
24+
bash test.sh
25+
cd ../InitNPETest
2426
bash test.sh

0 commit comments

Comments
 (0)