From 3e0f5e9e44f4dbf2b04cb57bff01cc5f9de2713a Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Fri, 16 Aug 2013 08:57:16 +0800 Subject: [PATCH] Bug 402601. Don't allow EvalTypeId.fArguments to be null to avoid NPE:s in dependent code. The most probable case of arguments being null was fixed in ea53c271c9de4bcec078ddecce89bb8b1b806a8d. Change-Id: I9d90bd0d4d09839ff9ed0cbc79e599485e878513 Signed-off-by: Jacek Sieka Reviewed-on: https://git.eclipse.org/r/15522 Reviewed-by: Sergey Prigogin IP-Clean: Sergey Prigogin Tested-by: Sergey Prigogin --- .../dom/parser/cpp/semantics/EvalTypeId.java | 29 +++++++------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java index 1e49fbcd4e2..bd32c0f4468 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/dom/parser/cpp/semantics/EvalTypeId.java @@ -39,9 +39,11 @@ public class EvalTypeId extends CPPDependentEvaluation { public EvalTypeId(IType type, IASTNode pointOfDefinition, ICPPEvaluation... arguments) { this(type, findEnclosingTemplate(pointOfDefinition), arguments); } - public EvalTypeId(IType type, IBinding templateDefinition, ICPPEvaluation... arguments) { super(templateDefinition); + if (arguments == null) + throw new NullPointerException("arguments"); //$NON-NLS-1$ + fInputType= type; fArguments= arguments; } @@ -82,9 +84,6 @@ public class EvalTypeId extends CPPDependentEvaluation { public IValue getValue(IASTNode point) { if (isValueDependent()) return Value.create(this); - if (fArguments == null) - return Value.UNKNOWN; - if (isTypeDependent()) return Value.create(this); if (fOutputType instanceof ICPPClassType) { @@ -106,8 +105,6 @@ public class EvalTypeId extends CPPDependentEvaluation { @Override public boolean isValueDependent() { - if (fArguments == null) - return false; for (ICPPEvaluation arg : fArguments) { if (arg.isValueDependent()) return true; @@ -157,9 +154,7 @@ public class EvalTypeId extends CPPDependentEvaluation { @Override public ICPPEvaluation instantiate(ICPPTemplateParameterMap tpMap, int packOffset, ICPPClassSpecialization within, int maxdepth, IASTNode point) { - ICPPEvaluation[] args = null; - if (fArguments != null) - args = instantiateCommaSeparatedSubexpressions(fArguments, tpMap, packOffset, within, maxdepth, point); + ICPPEvaluation[] args= instantiateCommaSeparatedSubexpressions(fArguments, tpMap, packOffset, within, maxdepth, point); IType type = CPPTemplates.instantiateType(fInputType, tpMap, packOffset, within, point); if (args == fArguments && type == fInputType) return this; @@ -170,16 +165,14 @@ public class EvalTypeId extends CPPDependentEvaluation { public ICPPEvaluation computeForFunctionCall(CPPFunctionParameterMap parameterMap, int maxdepth, IASTNode point) { ICPPEvaluation[] args = fArguments; - if (fArguments != null) { - for (int i = 0; i < fArguments.length; i++) { - ICPPEvaluation arg = fArguments[i].computeForFunctionCall(parameterMap, maxdepth, point); - if (arg != fArguments[i]) { - if (args == fArguments) { - args = new ICPPEvaluation[fArguments.length]; - System.arraycopy(fArguments, 0, args, 0, fArguments.length); - } - args[i] = arg; + for (int i = 0; i < fArguments.length; i++) { + ICPPEvaluation arg = fArguments[i].computeForFunctionCall(parameterMap, maxdepth, point); + if (arg != fArguments[i]) { + if (args == fArguments) { + args = new ICPPEvaluation[fArguments.length]; + System.arraycopy(fArguments, 0, args, 0, fArguments.length); } + args[i] = arg; } } if (args == fArguments)