Skip to content

Commit

Permalink
Silence sun.misc.unsafe warnings with separate compilation
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Helwer <2n8rn1w1f@mozmail.com>
  • Loading branch information
ahelwer committed Jun 6, 2024
1 parent 2bfa142 commit 80a7341
Showing 1 changed file with 46 additions and 5 deletions.
51 changes: 46 additions & 5 deletions tlatools/org.lamport.tlatools/customBuild.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,50 @@
==================================================================
= This code uses sun.misc.Unsafe for manual memory management in =
= the class src/tlc2/tool/fp/LongArray.java. This unsafe API is =
= marked as internal meaning it can change without warning. Java =
= emits a lot of warnings about this and makes it essentially =
= impossible to silence them, so just ignore them. The unsafe =
= API is in the process of being standardized in newer versions =
= of Java and we will switch to that as soon as possible. =
= marked as internal meaning it can change without warning. =
= Ordinarily this would result in a lot of compiler warnings, =
= but to reduce noise these have been explicitly silenced. If =
= the build fails after upgrading Java, it might be because this =
= API has been changed. =
==================================================================
</echo>
<mkdir dir="${class.dir}" />
<!--
Separate compilation step for files which must have their warnings
uniformly ignored. Java 11 removed the -XDignore.symbol.file compiler
parameter that worked in Java 8, so this is the new method. For some
reason Java *really, really* does not want you to silence the warnings
around sun.misc.Unsafe; every method that works when suppressing every
other warning does not work here (SuppressWarning annotations,
-Xlint:none compiler arg, even -nowarn). So, we are reduced to
compiling the files we want to ignore with an actual command line call,
then only printing the stderr output if the compilation fails.
-->
<exec executable="javac" errorproperty="PreCompileErrOutput" resultproperty="PreCompileResult" failonerror="false">
<arg line="--release ${java.release} -encoding UTF-8 -g:none -nowarn -Xlint:none"/>
<arg value="-sourcepath" />
<arg path="${src.dir}" />
<arg value="-d" />
<arg path="${class.dir}" />
<arg value="-classpath" />
<arg path="lib/javax.mail/mailapi-1.6.3.jar:lib/gson/gson-2.8.6.jar:lib/lsp/org.eclipse.lsp4j.jsonrpc_0.21.1.v20230829-0012.jar:lib/lsp/org.eclipse.lsp4j.debug_0.21.1.v20230829-0012.jar" />
<!--
Suppress sun.misc.Unsafe warnings. These warnings cannot be suppressed
using in-file annotations like ordinary warnings, so we must completely
ignore all warnings by compiling the file separately here.
-->
<arg file="${src.dir}/tlc2/tool/fp/LongArray.java" />
<!--
This file is generated by JavaCC and generates warnings, so we must
compile it separately here to silence them.
-->
<arg file="${src.dir}/tla2sany/parser/SimpleCharStream.java" />
</exec>
<fail message="${PreCompileErrOutput}">
<condition>
<isfailure code="${PreCompileResult}" />
</condition>
</fail>
<javac
includeantruntime="false"
srcdir="${src.dir}"
Expand All @@ -163,6 +199,11 @@
release="${java.release}"
encoding="UTF-8"
>
<!-- Exclude the files compiled separately up above to silence warnings. -->
<exclude name="tlc2/tool/fp/LongArray.java" />
<exclude name="tla2sany/parser/SimpleCharStream.java" />
<!-- Treat all warnings as errors. -->
<compilerarg value="-Werror" />
<classpath refid="project.classpath" />
<classpath>
<pathelement location="lib/javax.mail/mailapi-1.6.3.jar" />
Expand Down

0 comments on commit 80a7341

Please sign in to comment.