Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ final void onActivate() {
// launch the monitoringJob is necessary
if (monitoringJob != null) {
if (executorService == null) {
throw new IllegalStateException("ExecutorService must be set");
throw new IllegalStateException("ExecutorService is not set. Cannot launch monitoring job");
}
monitoringEvent = executorService.submit(monitoringJob.getMonitoringJob(this));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ final LocalReaderAdapter buildLocalReaderAdapter(ReaderSpi readerSpi) {
*/
final void checkStatus() {
if (!isRegistered) {
throw new IllegalStateException(
String.format("Plugin [%s] is not or no longer registered", pluginName));
throw new IllegalStateException("Plugin '" + pluginName + "' is not or no longer registered");
}
}

Expand Down Expand Up @@ -153,7 +152,7 @@ public final <T extends KeypleReaderExtension> T getReaderExtension(
checkStatus();
AbstractReaderAdapter reader = (AbstractReaderAdapter) getReader(readerName);
if (reader == null) {
throw new IllegalArgumentException("Reader [" + readerName + "] not found");
throw new IllegalArgumentException("Reader '" + readerName + "' is not found");
}
return reader.getExtension(readerExtensionClass);
}
Expand Down Expand Up @@ -213,7 +212,8 @@ public final CardReader findReader(String readerNameRegex) {
return reader;
}
} catch (PatternSyntaxException e) {
throw new IllegalArgumentException("readerNameRegex is invalid: " + e.getMessage(), e);
throw new IllegalArgumentException(
"Parameter 'readerNameRegex' has an invalid regex synthax: " + readerNameRegex, e);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ final List<CardSelectionResponseApi> transmitCardSelectionRequests(
cardSelectors, cardSelectionRequests, multiSelectionProcessing, channelControl);
} catch (UnexpectedStatusWordException e) {
throw new CardBrokenCommunicationException(
e.getCardResponse(), false, "An unexpected status word was received", e);
e.getCardResponse(),
false,
"An unexpected status word was received during the processing of the card selection requests",
e);
} finally {
if (logger.isDebugEnabled()) {
long timeStamp = System.nanoTime();
Expand All @@ -153,8 +156,7 @@ final List<CardSelectionResponseApi> transmitCardSelectionRequests(
*/
final void checkStatus() {
if (!isRegistered) {
throw new IllegalStateException(
String.format("This reader, %s, is not registered", getName()));
throw new IllegalStateException("Reader '" + getName() + "' is not registered");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ public int prepareSelection(

if (!(cardSelectionExtension instanceof CardSelectionExtensionSpi)) {
throw new IllegalArgumentException(
"The provided 'cardSelectionExtension' must be an instance of 'CardSelectionExtensionSpi'");
"Cannot cast 'cardSelectionExtension' to CardSelectionExtensionSpi. Actual type: "
+ cardSelectionExtension.getClass().getName());
}

/* keep the selection request */
Expand Down Expand Up @@ -205,7 +206,7 @@ public int importCardSelectionScenario(String cardSelectionScenario) {
JsonUtil.getParser().fromJson(cardSelectorsJsonArray.get(i), classOfCardSelector);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Original CardSelector type '" + cardSelectorsTypes.get(i) + "' not found", e);
"Original CardSelector type '" + cardSelectorsTypes.get(i) + "' is not found", e);
}
CardSelectionExtension cardSelection;
try {
Expand All @@ -217,7 +218,7 @@ public int importCardSelectionScenario(String cardSelectionScenario) {
} catch (ClassNotFoundException e) {
// Default card selection
logger.warn(
"Original CardSelection type '{}' not found. Replaced by default type '{}' for deserialization",
"Original CardSelection type '{}' is not found. Replaced by default type '{}' for deserialization",
cardSelectionsTypes.get(i),
CardSelectionAdapter.class.getName());
cardSelection =
Expand Down Expand Up @@ -282,7 +283,10 @@ public void scheduleCardSelectionScenario(
((ObservableRemoteReaderAdapter) observableCardReader)
.scheduleCardSelectionScenario(cardSelectionScenario, notificationMode);
} else {
throw new IllegalArgumentException("Not a Keyple reader implementation");
throw new IllegalArgumentException(
"Cannot cast 'observableCardReader' to ObservableLocalReaderAdapter or ObservableRemoteReaderAdapter. "
+ "Actual type: "
+ observableCardReader.getClass().getName());
}
}

Expand Down Expand Up @@ -333,10 +337,15 @@ public CardSelectionResult importProcessedCardSelectionScenario(
processedCardSelectionScenario,
new TypeToken<ArrayList<CardSelectionResponseApi>>() {}.getType());
} catch (JsonSyntaxException e) {
throw new IllegalArgumentException("Input string is invalid: " + e.getMessage(), e);
throw new IllegalArgumentException(
"Parameter 'processedCardSelectionScenario' has an invalid JSON synthax: "
+ processedCardSelectionScenario,
e);
}
if (cardSelectionResponses == null) {
throw new IllegalArgumentException("Input string is null or empty");
throw new IllegalArgumentException(
"Parameter 'processedCardSelectionScenario' is null or empty: "
+ processedCardSelectionScenario);
}
return processCardSelectionResponses(cardSelectionResponses);
}
Expand Down Expand Up @@ -366,7 +375,7 @@ private CardSelectionResult processCardSelectionResponses(
smartCard = (SmartCard) cardSelections.get(index).parse(cardSelectionResponse);
} catch (ParseException e) {
throw new InvalidCardResponseException(
"Error occurred while parsing the card response: " + e.getMessage(), e);
"Failed to parse the card response: " + cardSelectionResponse, e);
} catch (UnsupportedOperationException e) {
logger.warn(
"Unable to parse card selection responses due to missing card extensions in runtime environment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ final class DistributedLocalServiceAdapter
private static final Logger logger =
LoggerFactory.getLogger(DistributedLocalServiceAdapter.class);

private static final String READER_NOT_FOUND_TEMPLATE =
"There is no local reader registered with the name [%s] or the associated plugin is no longer registered";

private final String name;
private final LocalServiceSpi localServiceSpi;

Expand Down Expand Up @@ -78,7 +75,7 @@ final class DistributedLocalServiceAdapter
public boolean isReaderContactless(String readerName) {
CardReader reader = SmartCardServiceProvider.getService().findReader(Pattern.quote(readerName));
if (reader == null) {
throw new IllegalStateException(String.format(READER_NOT_FOUND_TEMPLATE, readerName));
throw new IllegalStateException("Reader '" + readerName + "' is not registered");
}
return reader.isContactless();
}
Expand Down Expand Up @@ -230,8 +227,7 @@ void unregister() {
*/
private void checkStatus() {
if (!isRegistered) {
throw new IllegalStateException(
String.format("Service [%s] is not or no longer registered", name));
throw new IllegalStateException("Local service '" + name + "' is not registered");
}
}

Expand All @@ -255,7 +251,7 @@ private LocalReaderExecutor(String jsonData, String readerName) {
(AbstractReaderAdapter)
SmartCardServiceProvider.getService().findReader(Pattern.quote(readerName));
if (reader == null) {
throw new IllegalStateException(String.format(READER_NOT_FOUND_TEMPLATE, readerName));
throw new IllegalStateException("Reader '" + readerName + "' is not registered");
}
input = JsonUtil.getParser().fromJson(jsonData, JsonObject.class);
output = new JsonObject();
Expand Down Expand Up @@ -308,7 +304,7 @@ private String execute() {
releaseChannel();
break;
default:
throw new IllegalArgumentException(service.name());
throw new IllegalArgumentException("Unsupported reader service: " + service.name());
}
} catch (Exception e) {
output.add(JsonProperty.ERROR.getKey(), JsonUtil.getParser().toJsonTree(new BodyError(e)));
Expand Down Expand Up @@ -385,7 +381,7 @@ private void transmitCardSelectionRequests()
JsonUtil.getParser().fromJson(cardSelectorsJsonArray.get(i), classOfCardSelector);
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Original CardSelector type " + cardSelectorsTypes.get(i) + " not found", e);
"Original CardSelector type '" + cardSelectorsTypes.get(i) + "' is not found", e);
}
cardSelectors.add(cardSelector);
}
Expand Down Expand Up @@ -430,8 +426,7 @@ private void scheduleCardSelectionScenario() {
((ObservableRemoteReaderAdapter) reader)
.scheduleCardSelectionScenario(cardSelectionScenario, notificationMode);
} else {
throw new IllegalStateException(
String.format("Reader [%s] is not observable", reader.getName()));
throw new IllegalStateException("Reader '" + reader.getName() + "' is not observable");
}
}

Expand Down Expand Up @@ -552,7 +547,7 @@ private String execute() {
stopReaderDetection();
break;
default:
throw new IllegalArgumentException(service.name());
throw new IllegalArgumentException("Unsupported plugin service: " + service.name());
}
} catch (Exception e) {
output.add(JsonProperty.ERROR.getKey(), JsonUtil.getParser().toJsonTree(new BodyError(e)));
Expand Down Expand Up @@ -622,9 +617,7 @@ private void allocateReader() {
PoolPlugin poolPlugin = getPoolPlugin(readerGroupReference);
if (poolPlugin == null) {
throw new IllegalStateException(
String.format(
"There is no local pool plugin registered having the reader group name [%s]",
readerGroupReference));
"No pool plugin is registered for reader group reference: " + readerGroupReference);
}
CardReader reader = poolPlugin.allocateReader(readerGroupReference);

Expand Down Expand Up @@ -678,7 +671,8 @@ private void startReaderDetection() {
}
}
if (!isObservationStarted) {
throw new IllegalStateException("There is no observable local plugin");
throw new IllegalStateException(
"There is no observable local plugin. Unable to start reader detection");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,10 @@ private static JsonObject getJsonObject(String outputJson) throws Exception { //
throw new UnexpectedStatusWordException(null, false, message);
} else {
throw new RuntimeException(
String.format(
"The distributed message sender received an unknown error: code: %s, message: %s",
code, message));
"The distributed message sender received an unknown error: code="
+ code
+ ", message="
+ message);
}
} else {
// Standard error.
Expand All @@ -178,9 +179,7 @@ private static JsonObject getJsonObject(String outputJson) throws Exception { //
*/
static void throwRuntimeException(Exception e) {
throw new RuntimeException( // NOSONAR
String.format(
"The distributed message sender received an unexpected error: %s", e.getMessage()),
e);
"The distributed message sender received an unexpected error", e);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public CardSelectionRequestSpi getCardSelectionRequest() {

@Override
public SmartCardSpi parse(CardSelectionResponseApi cardSelectionResponseApi) {
throw new UnsupportedOperationException("Method not supported for internal DTO");
throw new UnsupportedOperationException("Method 'parse' is not supported for internal DTO");
}

@Override
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/org/eclipse/keyple/core/service/JsonAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public AbstractApduException deserialize(
exceptionClass = (Class<? extends AbstractApduException>) Class.forName(type.getTypeName());
} catch (ClassNotFoundException e) {
throw new JsonParseException(
String.format(
"Exception [%s] not founded in runtime environment. Original message: %s",
type, message));
"Exception '"
+ type
+ "' is not found in runtime environment. Original message: "
+ message);
}

try {
Expand All @@ -100,12 +101,10 @@ public AbstractApduException deserialize(

} catch (NoSuchMethodException e) {
throw new JsonParseException(
String.format(
"No valid constructor found for exception [%s] with message [%s]", type, message));
"No valid constructor found for exception '" + type + "' with message: " + message, e);
} catch (InvocationTargetException | InstantiationException | IllegalAccessException e) {
throw new JsonParseException(
String.format(
"Error while trying to build exception [%s] with message [%s]", type, message));
"Failed to build exception '" + type + "' with message: " + message, e);
}
}
}
Expand Down Expand Up @@ -284,7 +283,7 @@ public CardSelectionScenarioAdapter deserialize(
.fromJson(cardSelectorsJsonArray.get(i), classOfCardSelector));
} catch (ClassNotFoundException e) {
throw new IllegalArgumentException(
"Original CardSelector type [" + cardSelectorsTypes.get(i) + "] not found", e);
"Original CardSelector type '" + cardSelectorsTypes.get(i) + "' is not found", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ public SortedSet<String> getReaderGroupReferences() {
return poolPluginSpi.getReaderGroupReferences();
} catch (PluginIOException e) {
throw new KeyplePluginException(
String.format(
"Pool plugin [%s] is unable to get reader group references: %s",
getName(), e.getMessage()),
e);
"Plugin '" + getName() + "' failed to retrieve reader group references", e);
}
}

Expand All @@ -105,9 +102,10 @@ public CardReader allocateReader(String readerGroupReference) {
readerSpi = poolPluginSpi.allocateReader(readerGroupReference);
} catch (PluginIOException e) {
throw new KeyplePluginException(
String.format(
"Pool plugin [%s] unable to allocate reader of reader group reference [%s]: %s",
getName(), readerGroupReference, e.getMessage()),
"Plugin '"
+ getName()
+ "' failed to allocate reader of reader group reference: "
+ readerGroupReference,
e);
}

Expand Down Expand Up @@ -152,10 +150,7 @@ public void releaseReader(CardReader reader) {
((LocalReaderAdapter) reader).getReaderSpi()); // NOSONAR nullity check is done above
} catch (PluginIOException e) {
throw new KeyplePluginException(
String.format(
"Pool plugin [%s] unable to release reader [%s]: %s",
getName(), reader.getName(), e.getMessage()),
e);
"Plugin '" + getName() + "' failed to release reader: " + reader.getName(), e);
} finally {
getReadersMap().remove(reader.getName());
((LocalReaderAdapter) reader).unregister();
Expand Down
Loading
Loading