diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java index e804916854f2..4f8d60284a79 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/JavaThreads.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -439,7 +439,11 @@ static void blockedOn(Target_sun_nio_ch_Interruptible b) { public static long getCurrentThreadId() { long id = currentVThreadId.get(); if (GraalDirectives.inIntrinsic()) { - ReplacementsUtil.dynamicAssert(id != 0 && id == getThreadId(Thread.currentThread()), "ids must match"); + // The condition may throw so we must manually wrap the assert in this if, otherwise the + // compiler is not allowed to remove the evaluation + if (ReplacementsUtil.REPLACEMENTS_ASSERTIONS_ENABLED) { + ReplacementsUtil.dynamicAssert(id != 0 && id == getThreadId(Thread.currentThread()), "ids must match"); + } } else { assert id != 0 && id == getThreadId(Thread.currentThread()); }