// Path: commons-eid-client/src/main/java/be/bosa/commons/eid/client/spi/Logger.java
// public interface Logger {
// 
// 	/**
// 	 * Error messages receiver.
// 	 *
// 	 * @param message the error message.
// 	 */
// 	void error(String message);
// 
// 	/**
// 	 * Debug messages receiver.
// 	 *
// 	 * @param message the debug message.
// 	 */
// 	void debug(String message);
// }


import org.apache.commons.lang3.exception.ExceptionUtils;
import be.bosa.commons.eid.client.spi.Logger;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CardTerminals;
import javax.smartcardio.TerminalFactory;
					logger.debug("Smart card service is on failure. Trying to reload the JDK SmartCard service.");
					reloadSmartCardService();
					return doList(state, false);
				}
			}
			throw e;
		}
	}

	/**
	 * This is ugly. But necessary ... <br>
	 * As long as https://bugs.openjdk.java.net/browse/JDK-8026326 is opened <br>
	 * Inspiration found in https://stackoverflow.com/a/26470094/3761154
	 */
	private synchronized void reloadSmartCardService() {
		try {
			Class pcscterminal = Class.forName("sun.security.smartcardio.PCSCTerminals");
			Field contextId = pcscterminal.getDeclaredField("contextId");
			contextId.setAccessible(true);

			if (contextId.getLong(pcscterminal) == 0L) {
				return;
			}

			// First get a new context value
			Class<?> pcsc = Class.forName("sun.security.smartcardio.PCSC");
			Method SCardEstablishContext =
					pcsc.getDeclaredMethod("SCardEstablishContext", Integer.TYPE);
			SCardEstablishContext.setAccessible(true);

// Path: commons-eid-client/src/main/java/be/bosa/commons/eid/client/spi/Logger.java
// public interface Logger {
// 
// 	/**
// 	 * Error messages receiver.
// 	 *
// 	 * @param message the error message.
// 	 */
// 	void error(String message);
// 
// 	/**
// 	 * Debug messages receiver.
// 	 *
// 	 * @param message the debug message.
// 	 */
// 	void debug(String message);
// }


// Path: commons-eid-client/src/main/java/be/bosa/commons/eid/client/impl/CardTerminalsProxy.java
import org.apache.commons.lang3.exception.ExceptionUtils;
import be.bosa.commons.eid.client.spi.Logger;
import static java.util.Objects.requireNonNull;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;
import java.util.Optional;
import javax.smartcardio.CardException;
import javax.smartcardio.CardTerminal;
import javax.smartcardio.CardTerminals;
import javax.smartcardio.TerminalFactory;

					logger.debug("Smart card service is on failure. Trying to reload the JDK SmartCard service.");
					reloadSmartCardService();
					return doList(state, false);
				}
			}
			throw e;
		}
	}

	/**
	 * This is ugly. But necessary ... <br>
	 * As long as https://bugs.openjdk.java.net/browse/JDK-8026326 is opened <br>
	 * Inspiration found in https://stackoverflow.com/a/26470094/3761154
	 */
	private synchronized void reloadSmartCardService() {
		try {
			Class pcscterminal = Class.forName("sun.security.smartcardio.PCSCTerminals");
			Field contextId = pcscterminal.getDeclaredField("contextId");
			contextId.setAccessible(true);

			if (contextId.getLong(pcscterminal) == 0L) {
				return;
			}

			// First get a new context value
			Class<?> pcsc = Class.forName("sun.security.smartcardio.PCSC");
			Method SCardEstablishContext =
					pcsc.getDeclaredMethod("SCardEstablishContext", Integer.TYPE);
			SCardEstablishContext.setAccessible(true);

			Field SCARD_SCOPE_USER = pcsc.getDeclaredField("SCARD_SCOPE_USER");