maven-surefire-plugin
3.5.4
diff --git a/examples/ledger-api/build.gradle b/examples/ledger-api/build.gradle
index b87a56bf..07863155 100644
--- a/examples/ledger-api/build.gradle
+++ b/examples/ledger-api/build.gradle
@@ -15,9 +15,11 @@ repositories {
dependencies {
implementation 'org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:2.5.7'
implementation 'org.json:json:20250517'
- testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
+ testImplementation platform('org.junit:junit-bom:6.0.0')
+ testImplementation 'org.junit.jupiter:junit-jupiter'
testImplementation 'org.assertj:assertj-core:3.27.6'
testImplementation 'org.mockito:mockito-core:5.20.0'
+ testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
shadowJar {
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/Logger.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/Logger.java
index 35720635..4e8a6e4a 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/Logger.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/Logger.java
@@ -14,11 +14,15 @@
/** Logger class to use throughout the Contract Implementation. */
public class Logger extends java.util.logging.Logger {
+ /**
+ * Subclasses must ensure that a parent logger is set appropriately, for example:
+ *
+ * {@code logger.setParent(java.util.logging.Logger.getLogger("org.hyperledger.fabric"))}
+ *
+ * @param name A name for the logger.
+ */
protected Logger(final String name) {
super(name, null);
-
- // ensure that the parent logger is set
- super.setParent(java.util.logging.Logger.getLogger("org.hyperledger.fabric"));
}
/**
@@ -26,7 +30,9 @@ protected Logger(final String name) {
* @return Logger
*/
public static Logger getLogger(final String name) {
- return new Logger(name);
+ Logger result = new Logger(name);
+ result.setParent(java.util.logging.Logger.getLogger("org.hyperledger.fabric"));
+ return result;
}
/** @param msgSupplier */
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/impl/SerializerRegistryImpl.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/impl/SerializerRegistryImpl.java
index 99a41e03..ecd406e8 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/impl/SerializerRegistryImpl.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/contract/routing/impl/SerializerRegistryImpl.java
@@ -8,6 +8,7 @@
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;
+import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -41,15 +42,20 @@ public SerializerInterface getSerializer(final String name, final Serializer.TAR
return contents.get(key);
}
- private SerializerInterface add(
- final String name, final Serializer.TARGET target, final Class clazz)
+ private void add(final String name, final Serializer.TARGET target, final Class> clazz)
throws InstantiationException, IllegalAccessException {
LOGGER.debug(() -> "Adding new Class " + clazz.getCanonicalName() + " for " + target);
final String key = name + ":" + target;
- final SerializerInterface newObj = clazz.newInstance();
- this.contents.put(key, newObj);
-
- return newObj;
+ try {
+ final SerializerInterface newObj =
+ (SerializerInterface) clazz.getDeclaredConstructor().newInstance();
+ this.contents.put(key, newObj);
+ } catch (InvocationTargetException | NoSuchMethodException e) {
+ InstantiationException wrapper = new InstantiationException(
+ "Exception constructing " + clazz.getCanonicalName() + ": " + e.getMessage());
+ wrapper.addSuppressed(e);
+ throw wrapper;
+ }
}
/**
@@ -67,10 +73,10 @@ public void findAndSetContents() throws InstantiationException, IllegalAccessExc
final Set seenClass = new HashSet<>();
try (ScanResult scanResult = classGraph.scan()) {
- for (final ClassInfo classInfo :
- scanResult.getClassesWithAnnotation(this.ANNOTATION_CLASS.getCanonicalName())) {
+ for (final ClassInfo classInfo : scanResult.getClassesWithAnnotation(ANNOTATION_CLASS.getCanonicalName())) {
LOGGER.debug(() -> "Found class with contract annotation: " + classInfo.getName());
- final Class cls = (Class) classInfo.loadClass();
+
+ final Class> cls = classInfo.loadClass();
LOGGER.debug("Loaded class");
final String className = cls.getCanonicalName();
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/QueryResultsIteratorImpl.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/QueryResultsIteratorImpl.java
index 89350204..fdddfb75 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/QueryResultsIteratorImpl.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/impl/QueryResultsIteratorImpl.java
@@ -107,7 +107,7 @@ public T next() {
}
@Override
- public void close() throws Exception {
+ public void close() {
final ByteString requestPayload = QueryStateClose.newBuilder()
.setId(currentQueryResponse.getId())
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIterator.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIterator.java
index e31dfcb6..f37b6cab 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIterator.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIterator.java
@@ -12,4 +12,7 @@
*
* @param the type of elements returned by the iterator
*/
-public interface QueryResultsIterator extends Iterable, AutoCloseable {}
+public interface QueryResultsIterator extends Iterable, AutoCloseable {
+ @Override
+ void close();
+}
diff --git a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIteratorWithMetadata.java b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIteratorWithMetadata.java
index b5c45cfa..9bed89aa 100644
--- a/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIteratorWithMetadata.java
+++ b/fabric-chaincode-shim/src/main/java/org/hyperledger/fabric/shim/ledger/QueryResultsIteratorWithMetadata.java
@@ -18,4 +18,7 @@
public interface QueryResultsIteratorWithMetadata extends Iterable, AutoCloseable {
/** @return Query Metadata */
QueryResponseMetadata getMetadata();
+
+ @Override
+ void close();
}