From 2da72ad05c5cf05ca81e0fa64abf4b6fef4896a4 Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Fri, 23 Nov 2018 10:31:28 +0100 Subject: [PATCH] LUCENE-8570: Fix possible NPE in the attribute reflection of the Nori's PartOfSpeechAttributeImpl --- .../ko/tokenattributes/PartOfSpeechAttributeImpl.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lucene/analysis/nori/src/java/org/apache/lucene/analysis/ko/tokenattributes/PartOfSpeechAttributeImpl.java b/lucene/analysis/nori/src/java/org/apache/lucene/analysis/ko/tokenattributes/PartOfSpeechAttributeImpl.java index 2e516897ba6..fbd637f92b2 100644 --- a/lucene/analysis/nori/src/java/org/apache/lucene/analysis/ko/tokenattributes/PartOfSpeechAttributeImpl.java +++ b/lucene/analysis/nori/src/java/org/apache/lucene/analysis/ko/tokenattributes/PartOfSpeechAttributeImpl.java @@ -62,11 +62,12 @@ public class PartOfSpeechAttributeImpl extends AttributeImpl implements PartOfSp @Override public void reflectWith(AttributeReflector reflector) { - reflector.reflect(PartOfSpeechAttribute.class, "posType", getPOSType().name()); - Tag leftPOS = getLeftPOS(); - reflector.reflect(PartOfSpeechAttribute.class, "leftPOS", leftPOS.name() + "(" + leftPOS.description() + ")"); - Tag rightPOS = getRightPOS(); - reflector.reflect(PartOfSpeechAttribute.class, "rightPOS", rightPOS.name() + "(" + rightPOS.description() + ")"); + String posName = getPOSType() == null ? null : getPOSType().name(); + String rightPOS = getRightPOS() == null ? null : getRightPOS().name() + "(" + getRightPOS().description() + ")"; + String leftPOS = getLeftPOS() == null ? null : getLeftPOS().name() + "(" + getLeftPOS().description() + ")"; + reflector.reflect(PartOfSpeechAttribute.class, "posType", posName); + reflector.reflect(PartOfSpeechAttribute.class, "leftPOS", leftPOS); + reflector.reflect(PartOfSpeechAttribute.class, "rightPOS", rightPOS); reflector.reflect(PartOfSpeechAttribute.class, "morphemes", displayMorphemes(getMorphemes())); }