efegokdemir commented on code in PR #177:
URL: https://github.com/apache/maven-shared-jar/pull/177#discussion_r4149408395
##########
src/main/java/org/apache/maven/shared/jar/identification/hash/JarBytecodeHashAnalyzer.java:
##########
@@ -43,25 +43,46 @@
public class JarBytecodeHashAnalyzer implements JarHashAnalyzer {
private final Logger logger = LoggerFactory.getLogger(getClass());
+ /**
+ * Computes the bytecode hash while retaining the historical null-on-error
behaviour.
+ *
+ * @param jarAnalyzer the JAR analyzer to use
+ * @return the hash, or {@code null} when the hash cannot be computed
+ * @deprecated use {@link #computeHashCode(JarAnalyzer)} when the failure
must be handled by the caller
+ */
+ @Deprecated
+ @Override
public String computeHash(JarAnalyzer jarAnalyzer) {
+ try {
+ return computeHashCode(jarAnalyzer);
+ } catch (IOException e) {
+ logger.warn("Unable to calculate the hashcode.", e);
+ return null;
+ }
+ }
+
+ /**
+ * Computes the bytecode hash and reports I/O failures to the caller.
+ *
+ * @param jarAnalyzer the JAR analyzer to use
+ * @return the computed hash
+ * @throws IOException if a class entry cannot be read
+ */
+ public String computeHashCode(JarAnalyzer jarAnalyzer) throws IOException {
Review Comment:
Applied in : made final. passes; Maven execution remains unavailable
locally because this environment has no Java runtime or Maven installation.
##########
src/main/java/org/apache/maven/shared/jar/identification/exposers/RepositorySearchExposer.java:
##########
@@ -77,9 +83,13 @@ public void expose(JarIdentification identification,
JarAnalyzer jarAnalyzer) {
repohits.addAll(repositoryHashSearch.searchFileHash(hash));
}
- String bytecodehash = bytecodeHashAnalyzer.computeHash(jarAnalyzer);
- if (bytecodehash != null) {
-
repohits.addAll(repositoryHashSearch.searchBytecodeHash(bytecodehash));
+ try {
+ String bytecodehash =
bytecodeHashAnalyzer.computeHashCode(jarAnalyzer);
+ if (bytecodehash != null) {
Review Comment:
Implemented in 7d3e65c. computeHashCode either returns the cached bytecode
digest or computes and stores one; I removed the obsolete null check from
RepositorySearchExposer and updated the hash analyzer test to exercise this
checked, non-null method. git diff --check passes. Maven tests could not run
because no Java runtime or Maven installation is available locally.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]