Add correct NullPointer handling to card recognition event emission
@@ -12,6 +12,7 @@ package org.openecard.sal;
import iso.std.iso_iec._24727.tech.schema.CardInfoType;
import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType;
+import iso.std.iso_iec._24727.tech.schema.ConnectionHandleType.RecognitionInfo;
import iso.std.iso_iec._24727.tech.schema.GetIFDCapabilities;
import iso.std.iso_iec._24727.tech.schema.GetIFDCapabilitiesResponse;
import iso.std.iso_iec._24727.tech.schema.GetStatus;
@@ -46,7 +47,6 @@ import org.openecard.common.sal.state.SalStateManager;
import org.openecard.common.sal.state.cif.CardInfoWrapper;
import org.openecard.common.util.ByteUtils;
import org.openecard.common.util.HandlerBuilder;
-import org.openecard.common.util.HandlerUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -312,13 +312,16 @@ public class SalEventManager {
LOG.info("Card with ATR={} inserted.", ByteUtils.toHexString(slot.getATRorATS()));
ConnectionHandleType handle = makeUnknownCardHandle(ifdName, newSlot, slotCapabilities);
- LOG.debug("Starting recognition for terminal {}.", ifdName);
// perform recognition
- handle = recogniseCard(handle);
- if (handle.getRecognitionInfo() != null) {
- String type = handle.getRecognitionInfo().getCardType();
+ RecognitionInfo recognitionInfo = recogniseCard(handle);
+ if (recognitionInfo != null) {
+ LOG.debug("Starting recognition for terminal {}.", ifdName);
+ handle.setRecognitionInfo(recognitionInfo);
+
+ String type = recognitionInfo.getCardType();
LOG.info("Recognised card type={}", type);
CardInfoType cif = env.getRecognition().getCardInfo(type);
+ if (cif != null) {
// add card to SAL state
// TODO: add interface protocol, but it looks like it was never used so probably ok to leave it null
try {
@@ -329,7 +332,12 @@ public class SalEventManager {
}
env.getEventDispatcher().notify(EventType.CARD_RECOGNIZED, new IfdEventObject(handle));
+ } else {
+ LOG.info("No card info evailable for type={}", type);
+ }
+ } else {
+ LOG.debug("No card regonition for terminal {}.", ifdName);
}
} else if (!terminalAdded && !cardPresent && cardWasPresent) {
@@ -395,21 +403,14 @@ public class SalEventManager {
return false;
}
- private ConnectionHandleType recogniseCard(ConnectionHandleType handle) {
- ConnectionHandleType result = handle;
+ private RecognitionInfo recogniseCard(ConnectionHandleType handle) {
try {
- ConnectionHandleType.RecognitionInfo type;
- type = env.getRecognition().recognizeCard(ctx, handle.getIFDName(), handle.getSlotIndex());
- if (type != null) {
- result = HandlerUtils.copyHandle(handle);
- result.setRecognitionInfo(type);
- }
+ return env.getRecognition().recognizeCard(ctx, handle.getIFDName(), handle.getSlotIndex());
} catch (RecognitionException ex) {
LOG.error("Error during card recognition.", ex);
+ return null;
}
- return result;
}
-
}
}
