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

Bugfix/1430 do not get unused value #1431

Merged

Conversation

aleksandy
Copy link
Contributor

Some cleanup and fix #1430

* using diamonds instead of explicit types;
* using already casted variable;
* using StringBuilder instead of String concatenation in loop;
* remove unnecessary method argument;
* remove redundant if-statement;
* using unwrap() instead of getDelegate() and type cast.
Copy link
Contributor

@asolntsev asolntsev left a comment

Choose a reason for hiding this comment

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

@xael-fry LTGT. Recommended to merge.

@straycat264
Copy link

I notice you've tidied up the section of code which started:
} else if (value instanceof PersistentCollection) { PersistentCollection col = (PersistentCollection) value; if (((PersistentCollection) value).wasInitialized()) {

Then proceeded to cascade the changes whether or not the collection was initialised.
Your tidy-up consists of dispensing with the wasInitialized() check - presumably because it was seemingly redundant.

My question: we've observed that this code causes saveOrCascade to load collections that cannot have had any modifications (as they're not currently loaded) before saving - which has led to performance issues. Is there a good reason for this behaviour? I assume so, but it would be good to know what that reason is.

@aleksandy
Copy link
Contributor Author

@straycat264, my changes didn't change code behaviour. It wasn't the goal of this PR.

The code in the if and else branches was the same, except that the PersistenceCollection in the if branch was passed through a cast of value, and the else used a separate variable col obtained by the same casting of the value.

In my opinion, your question should be moved to separate ticket. Perhaps here should use the approach used to processing PersistenceMap and do nothing if the collection is not initialized.

@xael-fry xael-fry added this to the 1.8.0 milestone Jul 15, 2023
@xael-fry xael-fry merged commit 586609b into playframework:master Jul 15, 2023
@xael-fry
Copy link
Member

Merge in master
Thanks @aleksandy

@JohannesBeranek
Copy link

@aleksandy @xael-fry

                            if (((PersistentCollection) value).wasInitialized()) {

This line was removed in this commit - why?

@aleksandy aleksandy deleted the bugfix/1430-do-not-get-unused-value branch August 23, 2023 16:49
@asolntsev
Copy link
Contributor

@JohannesBeranek I don't remember the details, but I believe the resulting code is effectively the same. I think it was a refactoring suggested by IDEA: it removed duplicated/unneeded line, thus leading to a shorter code that does the same job.

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

Successfully merging this pull request may close these issues.

NullPointer in JPABase.cascadeOrphans() caused by unused lines
5 participants