Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix deprecated check routines in ASTNode to also check since value #2874

Merged
merged 6 commits into from
Oct 26, 2024

Conversation

jjohnstn
Copy link
Contributor

What it does

Fixes deprecated warnings and errors being shown when the release setting is below the since threshold of a
deprecated method, type, field.

How to test

See issue.

Author checklist

@jjohnstn jjohnstn self-assigned this Aug 29, 2024
@jjohnstn jjohnstn added the bug Something isn't working label Aug 29, 2024
@jjohnstn jjohnstn added this to the 4.34 M1 milestone Sep 4, 2024
@jjohnstn jjohnstn force-pushed the deprecatedcheck branch 2 times, most recently from 2aba8be to cf61b9b Compare September 26, 2024 20:59
@jjohnstn
Copy link
Contributor Author

Hi @stephan-herrmann Can this be reviewed for M2?

@stephan-herrmann
Copy link
Contributor

Hi @stephan-herrmann Can this be reviewed for M2?

yes, M2 sounds realistic.

@stephan-herrmann stephan-herrmann modified the milestones: 4.34 M1, 4.34 M2 Sep 26, 2024
Copy link
Contributor

@stephan-herrmann stephan-herrmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dropped some suggestions for technical code simplification.

But I'm not sure we are on 100% firm ground conceptually:

  • do we know why editor and problems view show different results? A corresponding test in ReconcilerTests9 could be helpful to observe the difference.
  • I'd expect since values to be used mostly by JDK classes (because the version is a JDK version, not the version of 3rd party code) - and in the ticket the affected class was java.net.URL indeed.
    • in that case we shouldn't even see the class version with the deprecation annotations, IFF --release is used. This, too, is worth being double-checked.

@jjohnstn
Copy link
Contributor Author

jjohnstn commented Oct 8, 2024

I dropped some suggestions for technical code simplification.

But I'm not sure we are on 100% firm ground conceptually:

* do we know why editor and problems view show different results? A corresponding test in `ReconcilerTests9` could be helpful to observe the difference.

* I'd expect `since` values to be used mostly by JDK classes (because the version is a JDK version, not the version of 3rd party code) - and in the ticket the affected class was `java.net.URL` indeed.
  
  * in that case we shouldn't even see the class version with the deprecation annotations, IFF `--release` is used. This, too, is worth being double-checked.

Thanks for the code suggestions. I agree that the since value will likely only be used with JDK classes. I don't know how the release option works under the covers. Should the release option change the URL class in this case since we are talking deprecation and not an API addition, change, or removal? When I use JDK22 and specify compliance 19 with --release option checked, the Javadoc I get from the hover for the URL constructor in question is the JDK22 javadoc specifying the deprecation with since value.

@stephan-herrmann
Copy link
Contributor

I don't know how the release option works under the covers.

--release selects class stubs from withing ct.sym that represent the requested version of all JDK classes. I.e., we basically see the byte code minus the code attribute in exactly the requested version.

Should the release option change the URL class in this case since we are talking deprecation and not an API addition, change, or removal?

The signature entry for URL at versions 20+ contains:

    Deprecated: true
    RuntimeVisibleAnnotations:
      0: #42(#43=s#44)
        java.lang.Deprecated(
          since="20"
        )

When specifying --release 19 we get a version of URL without the deprecation info. Hence the compiler will not issue a warning when one of those contructors is used. This works as specified.

When I use JDK22 and specify compliance 19 with --release option checked, the Javadoc I get from the hover for the URL constructor in question is the JDK22 javadoc specifying the deprecation with since value.

That's a problem: we do have the correct information in byte code format, but we don't have version specific source attachment and javadoc! There is only the JDK22 version in your setup.

@stephan-herrmann
Copy link
Contributor

do we know why editor and problems view show different results? A corresponding test in ReconcilerTests9 could be helpful to observe the difference.

@jjohnstn did you succeed to write a test that demonstrates this difference between compiler and reconciler?

@jjohnstn
Copy link
Contributor Author

do we know why editor and problems view show different results? A corresponding test in ReconcilerTests9 could be helpful to observe the difference.

@jjohnstn did you succeed to write a test that demonstrates this difference between compiler and reconciler?

No, unfortunately I had to go to a wedding in Texas and have been doing some catch up in getting some UI changes into M2.

@jjohnstn
Copy link
Contributor Author

Hi @stephan-herrmann I added a test to ReconcilerTests9. Without the patch, there is a warning for both methods (one is deprecated since 9 and the other is deprecated since 10). With the patch, it only shows a warning for the method that is deprecated since 9. Is that sufficient?

@jjohnstn
Copy link
Contributor Author

@stephan-herrmann The reason for the warning in the editor is that the IMethodBinding returns true for isDeprecated() due to the compiler MethodBinding which sets the flag based on the ASTNode.isMethodUseDeprecated() method which I changed.

@stephan-herrmann
Copy link
Contributor

For the actual difference between editor and builder (which can only be demonstrated with deprecation in an original JDK class) I filed #3168, which comes with its own set of open questions, and hence may not be resolved in the near future. For that reason the current fix is a valid workaround for a situation that ideally shouldn't even occur, but does occur currently.

@stephan-herrmann stephan-herrmann merged commit 41b0c39 into eclipse-jdt:master Oct 26, 2024
10 checks passed
@stephan-herrmann
Copy link
Contributor

thanks @jjohnstn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

deprecation markers with since > BREE are not shown in Problems view but in Editor
2 participants