我在 eclipse 中创建了一个下面的 java 服务,并使用 PMD 插件查看了代码,但出现了以下错误
** 错误 **
DataflowAnomalyAnalysis: Found 'DD'-anomaly for variable 'result' (lines '80'-'83').
SignatureDeclareThrowsException: A method/constructor should not explicitly throw java.lang.Exception
java服务
@GetMapping("OCR/GetBarcodeRead")
@ApiOperation("Get result from Barcode Zxing library")
public String getBarcodeRead() throws Exception {
String result = new String();
try {
result = service.zxing();
} catch (Exception e) {
System.out.println(e);
result = "";
}
return result;
}
有人可以帮我解决这个问题吗?提前致谢
最佳答案
你的方法声明你抛出异常
,但你没有,所以删除它
public String getBarcodeRead() {
同时删除 new String()
并使用 ""
初始化它
String result = "";
关于java - 使用 eclipse 无法在 java 中解决 PMD 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60413465/