Merge pull request #3428 from adangel:issue-3420-inefficientstringbuffering

[java] Fix NPE in InefficientStringBuffering with Records #3428
This commit is contained in:
Andreas Dangel
2021-07-30 12:13:07 +02:00
3 changed files with 21 additions and 1 deletions

View File

@ -83,7 +83,7 @@ public class InefficientStringBufferingRule extends AbstractJavaRule {
if (name.getNameDeclaration() != null && name.getNameDeclaration() instanceof VariableNameDeclaration) {
VariableNameDeclaration vnd = (VariableNameDeclaration) name.getNameDeclaration();
AccessNode accessNodeParent = vnd.getAccessNodeParent();
if (accessNodeParent.isFinal()) {
if (accessNodeParent != null && accessNodeParent.isFinal()) {
return data;
}
}

View File

@ -451,6 +451,24 @@ public class Foo {
sb.append('}');
return sb.toString();
}
}
]]></code>
</test-code>
<test-code>
<description>[java] NPE in InefficientStringBuffering with Records #3420</description>
<expected-problems>0</expected-problems>
<code><![CDATA[
package a;
import java.io.InputStream;
import com.google.common.io.ByteStreams;
public record A(long from, long to) {
public InputStream a() {
return ByteStreams.limit(null, to - from);
}
}
]]></code>
</test-code>