diff --git a/build.gradle b/build.gradle index 3ca79b2d..c46c886b 100644 --- a/build.gradle +++ b/build.gradle @@ -46,22 +46,16 @@ subprojects { group = 'org.hyperledger.fabric-chaincode-java' version = rootProject.version - java { - sourceCompatibility = JavaVersion.VERSION_11 - targetCompatibility = JavaVersion.VERSION_11 - } - compileJava { - if (javaCompiler.get().metadata.languageVersion.canCompileOrRun(10)) { - options.release = 11 - } + options.release = 11 + options.compilerArgs += ['-Werror', '-Xlint:all'] } dependencies { implementation 'commons-cli:commons-cli:1.10.0' implementation 'commons-logging:commons-logging:1.3.5' - testImplementation platform('org.junit:junit-bom:5.13.4') + testImplementation platform('org.junit:junit-bom:6.0.0') testImplementation 'org.junit.jupiter:junit-jupiter' testRuntimeOnly 'org.junit.platform:junit-platform-launcher' testImplementation 'org.assertj:assertj-core:3.27.6' diff --git a/examples/fabric-contract-example-as-service/build.gradle b/examples/fabric-contract-example-as-service/build.gradle index 84809d6e..4c2aaeba 100644 --- a/examples/fabric-contract-example-as-service/build.gradle +++ b/examples/fabric-contract-example-as-service/build.gradle @@ -15,7 +15,8 @@ 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' diff --git a/examples/fabric-contract-example-gradle/build.gradle b/examples/fabric-contract-example-gradle/build.gradle index 8ccefd8b..eb1923b0 100644 --- a/examples/fabric-contract-example-gradle/build.gradle +++ b/examples/fabric-contract-example-gradle/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/examples/fabric-contract-example-maven/pom.xml b/examples/fabric-contract-example-maven/pom.xml index 1b198b95..dda0979e 100644 --- a/examples/fabric-contract-example-maven/pom.xml +++ b/examples/fabric-contract-example-maven/pom.xml @@ -18,10 +18,6 @@ 1.5.19 2.0.17 - - 5.13.4 - 1.13.1 - @@ -31,7 +27,19 @@ - + + + + org.junit + junit-bom + 6.0.0 + pom + import + + + + + @@ -69,19 +77,16 @@ org.junit.jupiter junit-jupiter-api - ${junit.jupiter.version} compile org.junit.jupiter junit-jupiter-params - ${junit.jupiter.version} test org.junit.jupiter junit-jupiter-engine - ${junit.jupiter.version} test @@ -102,7 +107,6 @@ src - 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(); }