Skip to content

Commit

Permalink
Default to a UTF-8 locale in Java stub template
Browse files Browse the repository at this point in the history
On non-macOS Unix, without any locale variable set, the OpenJDK defaults
to using ASCII rather than UTF-8 as the encoding for file system paths
(i.e., the value of the `sun.jnu.encoding` property).
  • Loading branch information
fmeum committed Apr 2, 2022
1 parent 2b3bd3e commit 848a6d8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,13 @@ if [ -z "$CLASSPATH_LIMIT" ]; then
is_windows && CLASSPATH_LIMIT=7000 || CLASSPATH_LIMIT=120000
fi

# On non-macOS Unix, without any locale variable set, the OpenJDK defaults to
# using ASCII rather than UTF-8 as the encoding for file system paths (i.e., the
# value of the sun.jnu.encoding property).
if ! is_macos && ! is_windows && [ -z "$LC_ALL" ] && [ -z "$LC_CTYPE" ] && [ -z "$LANG" ]; then
export LC_ALL=C.UTF-8
fi

if (("${#CLASSPATH}" > ${CLASSPATH_LIMIT})); then
export JACOCO_IS_JAR_WRAPPED=1
create_and_run_classpath_jar
Expand Down
28 changes: 28 additions & 0 deletions src/test/shell/bazel/unicode_filenames_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,32 @@ function test_utf8_source_artifact_in_bep() {
expect_log '"name":"pkg/srcs/ünïcödë fïlë.txt"'
}

function test_utf8_filename_in_java_test() {
touch WORKSPACE

mkdir pkg

cat >pkg/BUILD <<'EOF'
java_test(
name = "Test",
srcs = ["Test.java"],
main_class = "Test",
use_testrunner = False,
)
EOF

cat >pkg/Test.java <<'EOF'
import java.nio.file.Files;
import java.io.IOException;
class Test {
public static void main(String[] args) throws IOException {
Files.createTempFile("æøå", null);
}
}
EOF

bazel test //pkg:Test --test_output=errors 2>$TEST_log || fail "Test should pass"
}

run_suite "Tests for handling of Unicode filenames"

0 comments on commit 848a6d8

Please sign in to comment.