Skip to content

Commit

Permalink
fix: prevent NPE when invalid data is injected into Qute template
Browse files Browse the repository at this point in the history
Signed-off-by: Fred Bricon <[email protected]>
  • Loading branch information
fbricon committed Jun 30, 2023
1 parent 795b56e commit 0cce8eb
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.redhat.qute.commons.datamodel.DataModelBaseTemplate;
import com.redhat.qute.commons.datamodel.DataModelParameter;
import com.redhat.qute.commons.datamodel.DataModelTemplate;
import org.jetbrains.annotations.Nullable;

import static com.redhat.devtools.intellij.qute.psi.internal.QuteJavaConstants.JAVA_LANG_OBJECT_TYPE;
/**
Expand Down Expand Up @@ -60,16 +61,21 @@ public TemplateDataCollector(DataModelBaseTemplate<DataModelParameter> template,
protected boolean visitParameter(Object name, Object type) {
String paramName = null;
if (name instanceof PsiLiteral) {
paramName = ((PsiLiteral) name).getValue().toString();
@Nullable Object literalValue = ((PsiLiteral) name).getValue();
if (literalValue != null) {
paramName = literalValue.toString();
}
}
if (paramName != null) {
String paramType = JAVA_LANG_OBJECT_TYPE;
if (type instanceof PsiExpression) {
PsiType binding = ((PsiExpression) type).getType();
paramType = binding.getCanonicalText();
if (binding != null) {
paramType = binding.getCanonicalText();
}
}

if (paramName != null && template.getParameter(paramName) == null) {
if (template.getParameter(paramName) == null) {
DataModelParameter parameter = new DataModelParameter();
parameter.setKey(paramName);
parameter.setSourceType(paramType);
Expand Down

0 comments on commit 0cce8eb

Please sign in to comment.