java - 使用 eclipse 无法在 java 中解决 PMD 错误

标签 java eclipse spring-boot exception pmd

我在 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/

相关文章:

java - 覆盖接口(interface)中的java泛型方法

java - virtuoso-opensource : using jenaprovider, 如何从文件而不是从 URL 读取数据?

c++ - 使用 Eclipse IDE 在 C++ 中编写 GUI 需要做什么?

Java Util Logging 重定向到 Log4j2 不适用于 Spring Boot 应用程序

java - spring boot 无法使用 Intellij 连接 MYSQL 数据库

java - Spring MVC quartz : how to set the scheduler from the view or a html page

java - addActionListener 上的语法错误

java - 使用 Eclipse 调试 xslt 时出现 JVM 错误

java - 无法将图像绘制到 JFrame

java - 发生异常后,如何使用 PostgreSQL 在 Spring Boot 中继续事务?