Is intent to *check* or *set* assertions?

Codrut Stancu codrut.stancu at oracle.com
Mon Dec 25 03:58:46 UTC 2017


The code is correct. The method returns true if assertions are enabled, false otherwise. If assertions are enabled then the "assert assertionsEnabled = true" line is executed and sets the variable to true, which also causes the assertion check to pass. If assertions are disabled then the "assert assertionsEnabled = true" line is never executed, so the variable remains false. Thus the intent of this method is to answer the question: "Are the assertions enabled?".

Codrut Stancu

On Dec 24, 2017 5:25 PM, Joel Buckley wrote: > > Hi Graal-dev, > > In Substrate-Util.java[1], is the intent to *check* and/or *set* assertions to *true*? > > >     /** >      * Checks whether assertions are enabled in the VM. >      * >      * @return true if assertions are enabled. >      */ >     @SuppressWarnings("all") >     public static boolean assertionsEnabled() { >         boolean assertionsEnabled = false; >         assert assertionsEnabled = true; // should this be “== true”? >         return assertionsEnabled; // Otherwise, this is always true... >     } > > > Thanks, > Joel. > > [1]https://github.com/graalvm/graal/blob/master/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateUtil.java >


More information about the graal-dev mailing list