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

Aliasing: test constructor declarations #3337

Merged

Conversation

aditya3434
Copy link
Contributor

@aditya3434 aditya3434 commented May 28, 2020

The Aliasing checker gives a "unique.leaked" error when the super() class of a @unique annotated class is @MaybeAliased. This is useful for subclasses whose unique objects can leak into parent class methods. Classes that don't inherit from other classes, inherit from Object class as default which is @MaybeAliased according to the Aliasing Checker, hence, their constructors give a redundant "unique.leaked" error. The solution is to annotate the Object class as @unique in the annotated JDK (https://github.com/typetools/jdk). This would prevent @unique parent classes to leak their objects in the super() function.

This PR should be merged along with the annotated JDK pull request.
(typetools/jdk#52)

package java.lang;

class Object {
@Unique Object();
Copy link
Member

Choose a reason for hiding this comment

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

Why is this annotation being added in a jdk.astub file rather than in the annotated JDK, https://github.com/typetools/jdk?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added an .astub file to limit my changes to the Aliasing Checker directory itself and not disturb the workings of the other checkers. However, I have made changes in the annotated JDK and the resulting code still fixes the issue. It passed through all the checker tests but gives a "build failed for target 'run-test'" error in the build_jdk11u test when using Azure pipeline (not sure why).

Pull request : typetools/jdk#52

Copy link
Member

Choose a reason for hiding this comment

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

You should link related PRs from the PR descriptions, so that it is immediately clear that PRs need to be merged together.

You should remove this jdk.astub file from this PR now, as the changes from the related PR should be picked-up automatically.

Make the one suggested update in the jdk project and let's see whether the build just needs to re-run.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have removed the jdk.astub file from this PR and provided the link for the PR in description which needs to be merged together.

@@ -0,0 +1,16 @@
import org.checkerframework.common.aliasing.qual.Unique;

class ParentUniqueClass {
Copy link
Member

Choose a reason for hiding this comment

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

How about adding a top-level class around these two classes that has the same name as the file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added a top-level class around these two classes (with the same name) in my latest commit.


class ChildUniqueClass extends ParentUniqueClass {

@Unique ChildUniqueClass() {
Copy link
Member

Choose a reason for hiding this comment

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

Can you add another subclass that does raise an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In my latest commit, the ChildUniqueClass will raise an error since the ParentClass is not @unique.

@wmdietl wmdietl assigned aditya3434 and unassigned wmdietl Jun 5, 2020
import org.checkerframework.common.aliasing.qual.Unique;

public class UniqueConstructorTest {
// No need for @SuppressWarnings()
Copy link
Member

Choose a reason for hiding this comment

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

That comment should be combined with the one in the body, where you give the reason why no warning is required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have combined the comment with the one in the body.

public class UniqueConstructorTest {
// No need for @SuppressWarnings()
@Unique UniqueConstructorTest() {
// Doesn't raise unique.leaked error since it's a top parent class (@Unique Object subclass
Copy link
Member

Choose a reason for hiding this comment

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

What does top parent class mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Parent class extends UniqueConstructorTest and the Child class extends the parent class. Hence, I referred to the UniqueConstructorTest class as the "top parent class" (not related to the Parent class in the code) in the inheritance hierarchy. Since, it explicitly doesn't extend any class, it extends java.lang.Object class by default.

class ParentClass extends UniqueConstructorTest {

ParentClass() {
// Doesn't raise unique.leaked error since it's a non unique class with a unique parent
Copy link
Member

Choose a reason for hiding this comment

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

non-unique

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the correction in the comment

@aditya3434 aditya3434 assigned wmdietl and unassigned aditya3434 Jun 18, 2020
@wmdietl wmdietl changed the title 3313 leak in constructor error fix Aliasing: test constructor invocations Jun 23, 2020
@wmdietl wmdietl changed the title Aliasing: test constructor invocations Aliasing: test constructor declarations Jun 23, 2020
@wmdietl wmdietl assigned mernst and unassigned wmdietl Jun 23, 2020
@wmdietl
Copy link
Member

wmdietl commented Jun 23, 2020

@mernst Do you want to look at this again? We removed the stub file and this is now only a test case.
The failures are all in other type systems, so they must be unrelated to this change.

@mernst
Copy link
Member

mernst commented Jun 24, 2020

Since typetools/jdk#52 is closed, its branch should be deleted.
You might want to enable this feature on all your forks (I have found it useful and have also enabled it on typetools forks):
https://help.github.com/en/github/administering-a-repository/managing-the-automatic-deletion-of-branches

@mernst
Copy link
Member

mernst commented Jun 25, 2020

@aditya3434 Ping: Please delete the merged branch https://github.com/aditya3434/jdk/tree/3313-leak-in-constructor-error-fix. Then re-run CI (for example, by pulling master into this branch).

@mernst
Copy link
Member

mernst commented Jun 26, 2020

@aditya3434 Third request: Please delete the merged branch https://github.com/aditya3434/jdk/tree/3313-leak-in-constructor-error-fix. Then re-run CI (for example, by pulling master into this branch).

@aditya3434
Copy link
Contributor Author

@aditya3434 Third request: Please delete the merged branch https://github.com/aditya3434/jdk/tree/3313-leak-in-constructor-error-fix. Then re-run CI (for example, by pulling master into this branch).

I apologize for the delay. I have deleted the merged jdk branch and re-run CI on the pull request.

@mernst mernst removed their assignment Jun 30, 2020
@smillst
Copy link
Member

smillst commented Jun 30, 2020

@wmdietl I think this is ready to merge, but I don't think it fixes #3313. (I think #3336 fixes that issue?) Should I unlink that issue?

@wmdietl
Copy link
Member

wmdietl commented Jul 1, 2020

@smillst I agree that this didn't fix that issue. I've unlinked the issue.

@aditya3434 aditya3434 deleted the 3313-leak-in-constructor-error-fix branch July 11, 2020 06:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants