Java 来自 pmd:DataflowAnomalyAnalysis sslContext 的 UR 异常和 DR 异常
Java UR-anomaly and DR-anomaly from pmd:DataflowAnomalyAnalysis sslContext
我想要一些帮助来理解为什么当我在 运行 SonarQube 上尝试构建 Netty SslContext 的代码时,我从 pmd:DataflowAnomalyAnalysis 得到了 UR 异常和 DR 异常。
代码工作得很好,但我在 keystorePath 和 truststorePath 变量上得到了 UR 和 DR。
请指点?
谢谢
@Value("${server.ssl.key-store}") private String keyStorePath;
@Value("${server.ssl.key-store-password}") private String keyStorePassPhrase;
@Value("${server.ssl.key-password}") private String keyPassPhrase;
@Value("${server.ssl.key-store-type}") private String keyStoreType;
@Value("${server.ssl.trust-store}") private String trustStorePath;
@Value("${server.ssl.trust-store-password}") private String trustStorePassPhrase;
@Value("${server.ssl.trust-store-type}") private String trustStoreType;
public SslContext getSslContext() {
try {
final Path keystorePath = Paths.get(keyStorePath);
final KeyStore keyStore = KeyStore.getInstance(keyStoreType);
try (InputStream keyStoreFile = Files.newInputStream(keystorePath)) {
keyStore.load(keyStoreFile, keyStorePassPhrase.toCharArray());
}
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyPassPhrase.toCharArray());
final Path truststorePath = Paths.get(trustStorePath);
final KeyStore trustStore = KeyStore.getInstance(trustStoreType);
try (InputStream trustStoreFile = Files.newInputStream(truststorePath)) {
trustStore.load(trustStoreFile, trustStorePassPhrase.toCharArray());
}
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
return SslContextBuilder.forClient().keyManager(keyManagerFactory).trustManager(trustManagerFactory).build();
} catch (KeyStoreException | IOException | UnrecoverableKeyException | NoSuchAlgorithmException | CertificateException e) {
e.printStackTrace();
return null;
}
}
根据评论,最新的 PMD 7+ 版本确实不推荐使用此规则
我想要一些帮助来理解为什么当我在 运行 SonarQube 上尝试构建 Netty SslContext 的代码时,我从 pmd:DataflowAnomalyAnalysis 得到了 UR 异常和 DR 异常。
代码工作得很好,但我在 keystorePath 和 truststorePath 变量上得到了 UR 和 DR。
请指点? 谢谢
@Value("${server.ssl.key-store}") private String keyStorePath;
@Value("${server.ssl.key-store-password}") private String keyStorePassPhrase;
@Value("${server.ssl.key-password}") private String keyPassPhrase;
@Value("${server.ssl.key-store-type}") private String keyStoreType;
@Value("${server.ssl.trust-store}") private String trustStorePath;
@Value("${server.ssl.trust-store-password}") private String trustStorePassPhrase;
@Value("${server.ssl.trust-store-type}") private String trustStoreType;
public SslContext getSslContext() {
try {
final Path keystorePath = Paths.get(keyStorePath);
final KeyStore keyStore = KeyStore.getInstance(keyStoreType);
try (InputStream keyStoreFile = Files.newInputStream(keystorePath)) {
keyStore.load(keyStoreFile, keyStorePassPhrase.toCharArray());
}
final KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, keyPassPhrase.toCharArray());
final Path truststorePath = Paths.get(trustStorePath);
final KeyStore trustStore = KeyStore.getInstance(trustStoreType);
try (InputStream trustStoreFile = Files.newInputStream(truststorePath)) {
trustStore.load(trustStoreFile, trustStorePassPhrase.toCharArray());
}
final TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
return SslContextBuilder.forClient().keyManager(keyManagerFactory).trustManager(trustManagerFactory).build();
} catch (KeyStoreException | IOException | UnrecoverableKeyException | NoSuchAlgorithmException | CertificateException e) {
e.printStackTrace();
return null;
}
}
根据评论,最新的 PMD 7+ 版本确实不推荐使用此规则