Java Sonar问题:不应使用依赖默认系统编码的类和方法

Java Sonar问题:不应使用依赖默认系统编码的类和方法,java,sonarqube,inputstream,Java,Sonarqube,Inputstream,我在使用声纳检查代码质量时出错。这是一个错误 Classes and methods that rely on the default system encoding should not be used : Remove this use of constructor "InputStreamReader(InputStream)" 这是代码 private StringBuilder getServerResponse(URLConnection connection) throws IO

我在使用声纳检查代码质量时出错。这是一个错误

Classes and methods that rely on the default system encoding should not be used : Remove this use of constructor "InputStreamReader(InputStream)"
这是代码

private StringBuilder getServerResponse(URLConnection connection) throws IOException {
        final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String inputLine;
        final StringBuilder response = new StringBuilder();
        while ((inputLine = in.readLine()) != null) {
            response.append(inputLine);
        }
        in.close();
        return response;
    }
我在下面的一行中得到了这个错误:-

final BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
我试图找到解决办法,但没有成功。 任何指针都会有帮助

final BufferedReader in = new BufferedReader(new InputStreamReader(
 connection.getInputStream(), java.nio.charset.Charset.defaultCharset())
);
试着用这个。 有关问题的更多信息:

试着用这个。
关于这个问题的更多信息:

defaultCharset()
显然与不首先指定字符集没有什么不同。TBH这只是一个解决办法。它欺骗findbugs不报告问题。这就是我说“试试”的原因。当然,使用UTF是一个更好的解决方案。
defaultCharset()
显然与不首先指定字符集没有什么不同。TBH这只是一个解决办法。它欺骗findbugs不报告问题。这就是我说“试试”的原因。当然,使用UTF将是一个更好的解决方案。