From 30f03aa7f67b211cc007c96dabb4a5c78ffca231 Mon Sep 17 00:00:00 2001 From: Bas Leijdekkers Date: Fri, 12 Sep 2014 12:01:43 +0200 Subject: [PATCH] make "'Throwable' printed to 'System.out'" inspection warn in more cases --- .../maturity/ThrowablePrintedToSystemOutInspection.java | 8 ++------ .../ThrowablePrintedToSystemOutInspectionTest.java | 4 ++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspection.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspection.java index 49c63ef433b4..11bef5c40ed4 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspection.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspection.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2014 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. @@ -69,11 +69,7 @@ public class ThrowablePrintedToSystemOutInspection extends BaseInspection { return; } final PsiExpression argument = arguments[0]; - if (!(argument instanceof PsiReferenceExpression)) { - return; - } - final PsiReferenceExpression referenceExpression = (PsiReferenceExpression)argument; - if (!TypeUtils.expressionHasTypeOrSubtype(referenceExpression, CommonClassNames.JAVA_LANG_THROWABLE)) { + if (!TypeUtils.expressionHasTypeOrSubtype(argument, CommonClassNames.JAVA_LANG_THROWABLE)) { return; } final PsiMethod method = expression.resolveMethod(); diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspectionTest.java index d8ae40994bb1..a63132ee4437 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/maturity/ThrowablePrintedToSystemOutInspectionTest.java @@ -30,6 +30,10 @@ public class ThrowablePrintedToSystemOutInspectionTest extends LightInspectionTe "}\n"); } + public void testEvenSimpler() { + doStatementTest("System.out.println(/*Throwable argument 'new RuntimeException()' to 'System.out.println()' call*/new RuntimeException()/**/);"); + } + @Override protected InspectionProfileEntry getInspection() { return new ThrowablePrintedToSystemOutInspection();