You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Julian Reschke (JIRA)" <ji...@apache.org> on 2019/07/25 11:45:00 UTC
[jira] [Updated] (OAK-8212) ImporterImpl.importProperties prone to
NPE
[ https://issues.apache.org/jira/browse/OAK-8212?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Julian Reschke updated OAK-8212:
--------------------------------
Description:
the {{ImportImpl}} code at line 275 is prone to NPE because {{EffectiveNodeType.getPropertyDefinition(String, int, boolean)}} may return {{null}} (in contrast to the second variant that throws {{ConstraintViolationException}} if no matching definition is found.
the code looks as follows:
{code}
EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
if (def.isProtected()) {
...
}
{code}
proposed fix (adding a check for null):
{code}
EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
if (def == null) {
throw new ConstraintViolationException("No matching property definition found for " + pi.getName());
}
if (def.isProtected()) {
...
}
{code}
i spotted the issue while writing an import test for OAK-8190 with property type mismatch.
was:
the {{ImportImpl}} code at line 275 is prone to NPE because {{EffectiveNodeType.getPropertyDefinition(String, int, boolean) may return {{null}} (in contrast to the second variant that throws {{ConstraintViolationException}} if no matching definition is found.
the code looks as follows:
{code}
EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
if (def.isProtected()) {
...
}
{code}
proposed fix (adding a check for null):
{code}
EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
if (def == null) {
throw new ConstraintViolationException("No matching property definition found for " + pi.getName());
}
if (def.isProtected()) {
...
}
{code}
i spotted the issue while writing an import test for OAK-8190 with property type mismatch.
> ImporterImpl.importProperties prone to NPE
> ------------------------------------------
>
> Key: OAK-8212
> URL: https://issues.apache.org/jira/browse/OAK-8212
> Project: Jackrabbit Oak
> Issue Type: Bug
> Components: jcr
> Reporter: angela
> Assignee: angela
> Priority: Major
> Fix For: 1.14.0
>
>
> the {{ImportImpl}} code at line 275 is prone to NPE because {{EffectiveNodeType.getPropertyDefinition(String, int, boolean)}} may return {{null}} (in contrast to the second variant that throws {{ConstraintViolationException}} if no matching definition is found.
> the code looks as follows:
> {code}
> EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
> PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
> if (def.isProtected()) {
> ...
> }
> {code}
> proposed fix (adding a check for null):
> {code}
> EffectiveNodeType ent = effectiveNodeTypeProvider.getEffectiveNodeType(tree);
> PropertyDefinition def = ent.getPropertyDefinition(pi.getName(), pi.getType(), pi.isUnknownMultiple());
> if (def == null) {
> throw new ConstraintViolationException("No matching property definition found for " + pi.getName());
> }
> if (def.isProtected()) {
> ...
> }
> {code}
> i spotted the issue while writing an import test for OAK-8190 with property type mismatch.
--
This message was sent by Atlassian JIRA
(v7.6.14#76016)