GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [java] Fix method calls in type resolution by oowekyala · Pull Request #3061 · pmd/pmd

Conversation

@oowekyala

@oowekyala oowekyala commented Jan 15, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Describe the PR

Fix a bug in type resolution, by which expressions like a.m() have type a and not whatever the return type of m is. The fixed issues are instances of this same problem. It was not introduced in type resolution by 6.30.0, only made discoverable because UseEqualsToCompareStrings was updated to use type resolution in #2934.

This could be caused by unresolved local variables, though given how rotten the typeres code is I'm not sure. Other tests are failing now...


update

With these changes, in a call chain, the return type of method calls is now set on the PrimarySuffix that corresponds to the arguments. Previously, it was the PrimarySuffix for the method name, or the PrimaryPrefix, if the receiver is an ambiguous name (ASTName). This was inconsistent and hid the type of the receiver in that case.

Eg str.contains("") had the following type info (in the best case, whereas with the bug of #2976 the PrimaryExpression has the incorrect type string):

+ PrimaryExpression (type =  boolean)
  + PrimaryPrefix
     + Name(image = "str.contains", type = boolean)
  + PrimarySuffix
     + Arguments

where nothing hints that the receiver is of type string. Now it's

+ PrimaryExpression (type =  boolean)
  + PrimaryPrefix
     + Name(image = "str.contains", type = String)    <- this is the receiver type
  + PrimarySuffix (type = boolean)
     + Arguments

I think this is the best we can do on master. I don't want to add tests that will be thrown away when merging 7.0.x, I spent already too much time on this, so this only adds tests to the rules, not the typeres code.

Related issues

  • Fixes [java] CompareObjectsWithEquals: FP with array.length #2976
  • Fixes [java] CloseResource: false positive with reassignment detection #2977
  • Fixes [java] UseEqualsToCompareStrings: FP with "var" variables #2979
  • Fixes [java] UseEqualsToCompareStrings false positive with PMD 6.30.0 #3004

Ready?

  • Added unit tests for fixed bug/feature
  • Passing all unit tests
  • Complete build ./mvnw clean verify passes (checked automatically by travis)
  • Added (in-code) documentation (if needed)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
oowekyala added 5 commits January 15, 2021 23:56
@oowekyala
Test for pmd#3004
1fa9d08
@oowekyala
Tests for pmd#2976
3233ca0
@oowekyala
Tests for pmd#2979
7d87e89
@oowekyala
Fix type res of primary prefix for methods
4e96ee6
Consider things accessible if we can't resolve this class.
In particular, local variables were inaccessible, which is absurd.
@oowekyala
Fix DoNotUseThreads tests
cbceca9
@oowekyala oowekyala added this to the 6.31.0 milestone Jan 15, 2021
@oowekyala oowekyala changed the title [core] Fix method calls in type resolution [java] Fix method calls in type resolution Jan 15, 2021
oowekyala added 5 commits January 16, 2021 15:56
@oowekyala
Fix AvoidInstantiatingObjectsInLoopsRule
28ebe30
@oowekyala
Fix type resolver tests
292d526
The primary prefix now has the type of the receiver,
when it contains the name of a method call
@oowekyala
Remove useless code
20a2ab7
This made tests fail
@oowekyala
Fix bug with extra array dims
f9295c2
@oowekyala
Update test of CloseResource
f84ca18
@ghost

ghost commented Jan 16, 2021 •
edited by ghost
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
1 Message
📖 This changeset changes 16 violations,
introduces 1156 new violations, 0 new errors and 0 new configuration errors,
removes 276 violations, 0 errors and 0 configuration errors.
Full report
✅ This changeset changes 0 violations,
introduces 308 new violations, 1 new errors and 0 new configuration errors,
removes 407 violations, 0 errors and 0 configuration errors.
Full report
✅ This changeset changes 0 violations,
introduces 308 new violations, 1 new errors and 0 new configuration errors,
removes 407 violations, 0 errors and 0 configuration errors.
Full report

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala
oowekyala marked this pull request as ready for review January 16, 2021 16:33
This was linked to issues Jan 16, 2021
[java] CompareObjectsWithEquals: FP with array.length #2976
Closed
[java] UseEqualsToCompareStrings: FP with "var" variables #2979
Closed
@adangel

adangel commented Jan 16, 2021

Copy link
Copy Markdown
Member

Awesome, thanks for working on this! 🚀

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala
Test for pmd#2977
c1dca31
@oowekyala oowekyala mentioned this pull request Jan 16, 2021
[java] CloseResource: false positive with reassignment detection #2977
Closed
@adangel adangel self-assigned this Jan 19, 2021
adangel added 2 commits January 21, 2021 16:42
@adangel
[java] Fix NPE if generic array type couldn't be resolved
40bec48
Also add correct imports for GuardLogStatement tests
@adangel
[ci] Compile tests of spring framework for regression tester
a34ae3e
The test classes have not been compiled, that's why the typeres
can't always resolve the classes.
@adangel
adangel merged commit a34ae3e into pmd:master Jan 21, 2021
adangel added a commit that referenced this pull request Jan 21, 2021
@adangel
Merge pull request #3061 from oowekyala:typeres-fix-method-calls
8e42f6c
[java] Fix method calls in type resolution #3061
@oowekyala
oowekyala deleted the typeres-fix-method-calls branch January 21, 2021 17:46
@oowekyala oowekyala mentioned this pull request Jan 25, 2021
[java] AvoidInstantiatingObjectsInLoops: False positive - should not flag objects when assigned to lists/arrays #2207
Closed
@adangel adangel mentioned this pull request Jan 30, 2021
[java] AvoidInstantiatingObjectsInLoops - false positive with Collections #3088
Closed
@oowekyala oowekyala mentioned this pull request Jan 30, 2021
[java] StringBuilder/Buffer false negatives with typeres #2881
Closed
@oowekyala oowekyala linked an issue Feb 13, 2021 that may be closed by this pull request
[java] StringBuilder/Buffer false negatives with typeres #2881
Closed
@uhafner

uhafner commented Feb 15, 2021

Copy link
Copy Markdown

Does this fix also help for false negatives when comparing enumeration values? I still get warnings with 6.31.0 (see https://github.com/jenkinsci/warnings-ng-plugin/pull/774/checks?check_run_id=1804343680).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@oowekyala

oowekyala commented Feb 16, 2021

Copy link
Copy Markdown
Member Author

@uhafner This looks like the result of #2934 (merged for pmd 6.30). I don't think this PR is related

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

None yet

Projects

None yet

Milestone

6.31.0

Development

Successfully merging this pull request may close these issues.

[java] UseEqualsToCompareStrings false positive with PMD 6.30.0 [java] UseEqualsToCompareStrings: FP with "var" variables [java] CloseResource: false positive with reassignment detection [java] CompareObjectsWithEquals: FP with array.length [java] StringBuilder/Buffer false negatives with typeres

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@oowekyala @adangel @uhafner
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.