Skip to content

Commit

Permalink
Require the JVM default charset is UTF-8
Browse files Browse the repository at this point in the history
Java changed the default charset to UTF-8 in JEP 400 which is in Java 19
  • Loading branch information
dain committed Aug 12, 2023
1 parent 92ae114 commit d6f8a75
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Locale;
import java.util.OptionalLong;
Expand All @@ -48,6 +50,7 @@ public static void verifyJvmRequirements()
verifyUsingG1Gc();
verifyFileDescriptor();
verifySlice();
verifyUtf8();
}

private static void verify64BitJvm()
Expand Down Expand Up @@ -150,6 +153,14 @@ private static void verifySlice()
}
}

private static void verifyUtf8()
{
Charset defaultCharset = Charset.defaultCharset();
if (!defaultCharset.equals(StandardCharsets.UTF_8)) {
failRequirement("Trino requires that the default charset is UTF-8 (found %s). This can be set with the JVM command line option -Dfile.encoding=UTF-8", defaultCharset.name());
}
}

/**
* Perform a sanity check to make sure that the year is reasonably current, to guard against
* issues in third party libraries.
Expand Down
5 changes: 5 additions & 0 deletions docs/src/main/sphinx/installation/deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ as the JDK for Trino, as Trino is tested against that distribution.
Zulu is also the JDK used by the
[Trino Docker image](https://hub.docker.com/r/trinodb/trino).

If you are using Java 17 or 18, the JVM must be configured to use UTF-8 as the default charset by
adding `-Dfile.encoding=UTF-8` to `etc/jvm.config`. Starting with Java 19, the Java default
charset is UTF-8, so this configuration is not needed.

(requirements-python)=

### Python
Expand Down Expand Up @@ -136,6 +140,7 @@ The following provides a good starting point for creating `etc/jvm.config`:
-Djdk.nio.maxCachedBufferSize=2000000
-XX:+UnlockDiagnosticVMOptions
-XX:+UseAESCTRIntrinsics
-Dfile.encoding=UTF-8
# Disable Preventive GC for performance reasons (JDK-8293861)
-XX:-G1UsePreventiveGC
```
Expand Down

0 comments on commit d6f8a75

Please sign in to comment.