IG: fix AIOOBE (EA-131665)

This commit is contained in:
Bas Leijdekkers
2018-11-07 21:07:59 +01:00
parent 298fa9c3c7
commit 3fd978a24f
2 changed files with 15 additions and 3 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2003-2017 Dave Griffith, Bas Leijdekkers
* Copyright 2003-2018 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.
@@ -414,7 +414,7 @@ public class MethodCallUtils {
public static boolean isUsedAsSuperConstructorCallArgument(@NotNull PsiParameter parameter, boolean superMustBeLibrary) {
final PsiElement scope = parameter.getDeclarationScope();
if (!(scope instanceof PsiMethod)) {
if (!(scope instanceof PsiMethod) || !((PsiMethod)scope).isConstructor()) {
return false;
}
PsiMethod method = (PsiMethod)scope;
@@ -445,7 +445,8 @@ public class MethodCallUtils {
if (JavaPsiConstructorUtil.isSuperConstructorCall(call) && (!superMustBeLibrary || method instanceof PsiCompiledElement)) {
return true;
}
parameter = method.getParameterList().getParameters()[index];
final PsiParameter[] parameters = method.getParameterList().getParameters();
parameter = parameters[Math.min(index, parameters.length - 1)];
}
}
@@ -44,6 +44,17 @@ public class BooleanParameterInspectionTest extends LightInspectionTestCase {
"}");
}
public void testVarargs() {
doTest("class Y {" +
" public Y(boolean... b) {}" +
"}" +
"class X extends Y {" +
" public /*'public' constructor 'X()' with 'boolean' parameter*/X/**/(boolean b) {" +
" super(true, b);" +
" }" +
"}");
}
@Override
protected LocalInspectionTool getInspection() {
return new BooleanParameterInspection();