GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — [java] StringToString can not detect the case: getStringMethod().toString() by Drofff · Pull Request #2659 · pmd/pmd Conversation
|
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
@Drofff Thanks for the PR!
Could you please fix the merge conflict by rebasing or merging master into your branch? Then we get our regression tester running and see, if we introduced with these change any new false positives/false negatives.
Regarding the issue you are fixing: Be aware, that you are fixing only the case, where the called method is defined within the same class, e.g. the following case would not be covered:
public class A { public String methodReturningString() { return "foo"; } }
And in another file:
public class StringToStringFN { public static void main(String[] args) { A a = new A(); String s = a.methodReturningString().toString(); // <--- that is technically also a StringToString violation } }
I don't think, we can report this case yet. It would be a a lot more effort to cover this as well (in theory, the type resolution should give you the return type of the method call, but that's not working in PMD 6.x, maybe it'll be improved with PMD 7).
I don't want to say, that you should fix this as well, but just wanting to make sure, that you are aware of this. We probably should mention this on the fixed issue, as to avoid the expectation, that all possible cases are fixed, when we close the issue.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
ba790dd to
b48da45
Compare
|
@Drofff There seems to be a NPE, e.g. https://travis-ci.org/github/pmd/pmd/jobs/713606711#L13483 Can you have a look? That's the reason, why the regression tester still has no results.... |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@adangel thanks for your time! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Hi @Drofff ,
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Hello, @adangel. Thank you for your time! Your changes are constructive and meaningful. And in order to explain my previous commit, please, take a look at the test cases below: <test-code> <description>external class as a method parameter NullPointerException test</description> <expected-problems>1</expected-problems> <expected-linenumbers>8</expected-linenumbers> <code><![CDATA[ import org.springframework.context.MessageSourceResolvable; public class Foo { public Long getData(User usr) { return usr.getId(); } public String getData(MessageSourceResolvable msr) { return "MSR: " + msr.toString(); } public void bar() { String s = getData(new MessageSourceResolvable()).toString(); } } ]]></code> </test-code> <test-code> <description>variable as method call argument</description> <expected-problems>1</expected-problems> <code><![CDATA[ public class Foo { public void bar() { User user = new User(); String s = getId(user).toString(); } public String getId(User user) { return ""; } public int getId(Car car) { return 0; } } ]]></code> </test-code> <test-code> <description>method call as method call argument</description> <expected-problems>1</expected-problems> <code><![CDATA[ public class Foo { public void bar() { String s = getData(getLong()).toString(); } public long getLong() { return 0; } public String getData(long d) { return ""; } public long getData(String d) { return 0; } } ]]></code> </test-code> I'm sorry that I hadn't added these cases before. All the code from commit had been written to cover them. Are they correct? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the test cases, I've integrated them and fixed the implementation accordingly. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
[java] StringToString can not detect the case: getStringMethod().toString() #2659
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[java] StringToString can not detect the case: getStringMethod().toString()
There was an error while loading. Please reload this page.