Repository: jenkinsci/jenkins
File: core/src/main/java/jenkins/util/JSONSignatureValidator.java (Java)

Code before:
                                    + "but %s did not parse as a certificate. Skipping this file for now.",
                            cert.getParentFile().getAbsolutePath(),
                            cert.getAbsolutePath()), e);
                    continue;
                }
                try {
                    TrustAnchor certificateAuthority = new TrustAnchor((X509Certificate) certificate, null);
                    anchors.add(certificateAuthority);
                } catch (IllegalArgumentException e) {
                    LOGGER.log(Level.WARNING,
                            String.format("The name constraints in the certificate file %s could not be "
                                            + "decoded. Skipping this file for now.",
                            cert.getAbsolutePath()), e);
                }
            }
        }
        return anchors;
    }

    /**
     * Extracts a user-friendly message from an exception chain.
     *
     * @param e the exception to extract the message from
     * @return a concise, readable error message
     */
    private String getRootCauseMessage(Throwable e) {
        Throwable cause = e;
        while (cause.getCause() != null && cause.getCause() != cause) {
            cause = cause.getCause();
        }

        String message = cause.getMessage();
        if (message != null && !message.isEmpty()) {
            return message;
        }

        return cause.getClass().getSimpleName();
    }

    private static final Logger LOGGER = Logger.getLogger(JSONSignatureValidator.class.getName());
}


Review comment (bug):
Optional suggestion to annotate the argument so that spotbugs knows that the implementation expects that the argument is not null.  A null pointer exception will be reported if a null value is passed as the argument.

If you decide to adopt this suggestion, it is probably best to use the short form `@NonNull` and an import.
```suggestion
    private String getRootCauseMessage(@edu.umd.cs.findbugs.annotations.NonNull Throwable e) {
```

Code after:
                                    + "certificates or .txt files documenting the certificates, "
                                    + "but %s did not parse as a certificate. Skipping this file for now.",
                            cert.getParentFile().getAbsolutePath(),
                            cert.getAbsolutePath()), e);
                    continue;
                }
                try {
                    TrustAnchor certificateAuthority = new TrustAnchor((X509Certificate) certificate, null);
                    anchors.add(certificateAuthority);
                } catch (IllegalArgumentException e) {
                    LOGGER.log(Level.WARNING,
                            String.format("The name constraints in the certificate file %s could not be "
                                            + "decoded. Skipping this file for now.",
                            cert.getAbsolutePath()), e);
                }
            }
        }
        return anchors;
    }

    /**
     * Extracts a user-friendly message from an exception chain.
     *
     * @param e the exception to extract the message from
     * @return a concise, readable error message
     */
    private String getRootCauseMessage(@NonNull Throwable e) {
        Throwable cause = e;
        while (cause.getCause() != null && cause.getCause() != cause) {
            cause = cause.getCause();
        }

        String message = cause.getMessage();
        if (message != null && !message.isEmpty()) {
            return message;
        }

        return cause.getClass().getSimpleName();
    }

    private static final Logger LOGGER = Logger.getLogger(JSONSignatureValidator.class.getName());
}