Skip to content

Commit 984003d

Browse files
author
Alexey Semenyuk
committedJul 22, 2021
8268974: GetJREPath() JLI function fails to locate libjava.so if not standard Java launcher is used
Reviewed-by: almatvee, herrick, alanb
1 parent c1c4048 commit 984003d

File tree

2 files changed

+64
-7
lines changed

2 files changed

+64
-7
lines changed
 

‎src/java.base/unix/native/libjli/java_md_common.c

+14-7
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,27 @@ static char* findLastPathComponent(char *buffer, const char *comp) {
4545
/*
4646
* Removes the trailing file name and any intermediate platform
4747
* directories, if any, and its enclosing directory.
48+
* Second parameter is a hint about the type of a file. JNI_TRUE is for
49+
* shared libraries and JNI_FALSE is for executables.
4850
* Ex: if a buffer contains "/foo/bin/javac" or "/foo/bin/x64/javac", the
4951
* truncated resulting buffer will contain "/foo".
5052
*/
5153
static jboolean
52-
TruncatePath(char *buf)
54+
TruncatePath(char *buf, jboolean pathisdll)
5355
{
54-
// try bin directory, maybe an executable
55-
char *p = findLastPathComponent(buf, "/bin/");
56+
/*
57+
* If the file is a library, try lib directory first and then bin
58+
* directory.
59+
* If the file is an executable, try bin directory first and then lib
60+
* directory.
61+
*/
62+
63+
char *p = findLastPathComponent(buf, pathisdll ? "/lib/" : "/bin/");
5664
if (p != NULL) {
5765
*p = '\0';
5866
return JNI_TRUE;
5967
}
60-
// try lib directory, maybe a library
61-
p = findLastPathComponent(buf, "/lib/");
68+
p = findLastPathComponent(buf, pathisdll ? "/bin/" : "/lib/");
6269
if (p != NULL) {
6370
*p = '\0';
6471
return JNI_TRUE;
@@ -80,7 +87,7 @@ GetApplicationHome(char *buf, jint bufsize)
8087
} else {
8188
return JNI_FALSE;
8289
}
83-
return TruncatePath(buf);
90+
return TruncatePath(buf, JNI_FALSE);
8491
}
8592

8693
/*
@@ -95,7 +102,7 @@ GetApplicationHomeFromDll(char *buf, jint bufsize)
95102
if (dladdr((void*)&GetApplicationHomeFromDll, &info) != 0) {
96103
char *path = realpath(info.dli_fname, buf);
97104
if (path == buf) {
98-
return TruncatePath(buf);
105+
return TruncatePath(buf, JNI_TRUE);
99106
}
100107
}
101108
return JNI_FALSE;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
* version 2 for more details (a copy is included in the LICENSE file that
13+
* accompanied this code).
14+
*
15+
* You should have received a copy of the GNU General Public License version
16+
* 2 along with this work; if not, write to the Free Software Foundation,
17+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18+
*
19+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20+
* or visit www.oracle.com if you need additional information or have any
21+
* questions.
22+
*/
23+
24+
import jdk.jpackage.test.Annotations.Test;
25+
import jdk.jpackage.test.Annotations.Parameter;
26+
import jdk.jpackage.test.JPackageCommand;
27+
28+
/*
29+
* @test
30+
* @summary jpackage with values of --dest parameter breaking jpackage launcher
31+
* @requires (os.family == "linux")
32+
* @bug 8268974
33+
* @library ../helpers
34+
* @build jdk.jpackage.test.*
35+
* @modules jdk.jpackage/jdk.jpackage.internal
36+
* @compile LinuxWeirdOutputDirTest.java
37+
* @run main/othervm/timeout=540 -Xmx512m jdk.jpackage.test.Main
38+
* --jpt-run=LinuxWeirdOutputDirTest
39+
*/
40+
public class LinuxWeirdOutputDirTest {
41+
42+
@Test
43+
@Parameter("bin")
44+
@Parameter("lib")
45+
public void test(String outputPath) {
46+
JPackageCommand cmd = JPackageCommand.helloAppImage();
47+
cmd.setArgumentValue("--dest", cmd.outputDir().resolve(outputPath));
48+
cmd.executeAndAssertHelloAppImageCreated();
49+
}
50+
}

0 commit comments

Comments
 (0)
Please sign in to comment.