diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SynchronizationUtil.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SynchronizationUtil.java index 30b6a70d4692..297a862a2c1d 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SynchronizationUtil.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/SynchronizationUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2006-2010 Bas Leijdekkers + * Copyright 2006-2015 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,16 +25,14 @@ public class SynchronizationUtil { public static boolean isInSynchronizedContext(PsiElement element) { final PsiElement context = - PsiTreeUtil.getParentOfType(element, PsiMethod.class, - PsiSynchronizedStatement.class); + PsiTreeUtil.getParentOfType(element, PsiMethod.class, PsiSynchronizedStatement.class, PsiClass.class, PsiLambdaExpression.class); if (context instanceof PsiSynchronizedStatement) { return true; } - if (context == null) { + if (!(context instanceof PsiMethod)) { return false; } - final PsiModifierListOwner modifierListOwner = - (PsiModifierListOwner)context; + final PsiModifierListOwner modifierListOwner = (PsiModifierListOwner)context; return modifierListOwner.hasModifierProperty(PsiModifier.SYNCHRONIZED); } } \ No newline at end of file diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java new file mode 100644 index 000000000000..75e89d147a73 --- /dev/null +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/threading/call_to_native_method_while_locked/CallToNativeMethodWhileLocked.java @@ -0,0 +1,14 @@ +package com.siyeh.igtest.threading.call_to_native_method_while_locked; + +public class CallToNativeMethodWhileLocked { + + synchronized void a() { + Double.doubleToLongBits(9.7); + Runnable r = () -> { + Double.doubleToLongBits(123.4); + }; + new Object() { + long l = Double.doubleToLongBits(42.0); + }; + } +} diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspectionTest.java new file mode 100644 index 000000000000..ec87747a5bfb --- /dev/null +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/threading/CallToNativeMethodWhileLockedInspectionTest.java @@ -0,0 +1,36 @@ +/* + * Copyright 2000-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.siyeh.ig.threading; + +import com.intellij.codeInspection.InspectionProfileEntry; +import com.siyeh.ig.LightInspectionTestCase; +import org.jetbrains.annotations.Nullable; + +/** + * @author Bas Leijdekkers + */ +public class CallToNativeMethodWhileLockedInspectionTest extends LightInspectionTestCase { + + public void testCallToNativeMethodWhileLocked() { + doTest(); + } + + @Nullable + @Override + protected InspectionProfileEntry getInspection() { + return new CallToNativeMethodWhileLockedInspection(); + } +} \ No newline at end of file