diff --git a/java/java-analysis-impl/src/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspection.java b/java/java-analysis-impl/src/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspection.java index 7780683f7b54..fc34c31b7dcc 100644 --- a/java/java-analysis-impl/src/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspection.java +++ b/java/java-analysis-impl/src/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2010 Dave Griffith, Bas Leijdekkers + * Copyright 2003-2025 Dave Griffith, Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,8 +28,7 @@ public final class CallToNativeMethodWhileLockedInspection extends BaseInspectio @Override protected @NotNull String buildErrorString(Object... infos) { - return InspectionGadgetsBundle.message( - "call.to.native.method.while.locked.problem.descriptor"); + return InspectionGadgetsBundle.message("call.to.native.method.while.locked.problem.descriptor"); } @Override @@ -43,14 +42,14 @@ public final class CallToNativeMethodWhileLockedInspection extends BaseInspectio Set.of(CommonClassNames.JAVA_LANG_OBJECT, "java.lang.System", "sun.misc.Unsafe", "java.lang.invoke.MethodHandle"); @Override - public void visitMethodCallExpression( - @NotNull PsiMethodCallExpression expression) { + public void visitMethodCallExpression(@NotNull PsiMethodCallExpression expression) { final PsiMethod method = expression.resolveMethod(); if (method == null || !method.hasModifierProperty(PsiModifier.NATIVE)) return; final PsiClass containingClass = method.getContainingClass(); if (containingClass == null) return; - if (EXCLUDED_CLASS_NAMES.contains(containingClass.getQualifiedName())) return; + String name = containingClass.getQualifiedName(); + if (name != null && EXCLUDED_CLASS_NAMES.contains(name)) return; if (!SynchronizationUtil.isInSynchronizedContext(expression)) return; registerMethodCallError(expression); diff --git a/java/java-tests/testData/ig/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java b/java/java-tests/testData/ig/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java index 5481c971ee3c..3f359e994106 100644 --- a/java/java-tests/testData/ig/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java +++ b/java/java-tests/testData/ig/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java @@ -9,6 +9,12 @@ public class CallToNativeMethodWhileLocked { }; new Object() { long l = Double.doubleToRawLongBits(42.0); + + synchronized void x() { + y(); + } + + native void y(); }; Runnable s = () -> { assert Thread.holdsLock(this);