Skip to content

Make AztecAttributes immutable in order to stop crashes - #751

Merged
planarvoid merged 7 commits into
developfrom
make_aztec_attributes_immutable
Oct 31, 2018
Merged

Make AztecAttributes immutable in order to stop crashes#751
planarvoid merged 7 commits into
developfrom
make_aztec_attributes_immutable

Conversation

@planarvoid

Copy link
Copy Markdown
Contributor

This crash (in theory) shouldn't happen. This leads me to thinking that two independent threads are modifying the same AztecAttributes object and there is a race condition when setting/removing attributes. Making AztecAttributes immutable and passing always a copy should fix the problem. Let me know what you think.

Fix#705

Review

@0nko@malinajirka

malinajirka
malinajirka previously approved these changes Oct 15, 2018

@malinajirkamalinajirka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @planarvoid ! 👍 for making the AztecAttributes immutable!

LGTM! I've added couple of minor comments. We might also consider overriding add/remove Atrribute and making them deprecated. Wdyt?

return aztecAttributes
}

fun withValues(keyValues: Map<String, String>): AztecAttributes {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you considered calling withValue(keyValue: Pair<String, String>) in a loop? Creating a short living object (Pair) in a loop shouldn't have any performance impact.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

we'd also be creating a copy of AztecAttributes every time we call withValue. I'd rather do it the other way around and create a short living map and call withValues from within withValue, what do you think?


fun withoutValues(keys: List<String>): AztecAttributes {
val aztecAttributes = AztecAttributes(this)
for (key in keys) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Have you considered calling withoutValue(key: String) in a loop?

@malinajirka
malinajirka dismissed their stale reviewOctober 15, 2018 05:30

Failing tests

@planarvoid

Copy link
Copy Markdown
ContributorAuthor

@malinajirka No idea why the tests were failing. It's nothing I've touched. I've replaced two methods (withValue/withValues) with one with vararg params. Let me know what you think.

@malinajirka

Copy link
Copy Markdown
Contributor

@planarvoid These ImageCaptionTest.kt:453ImageCaptionTest.kt:502 two tests are failing and it seems you've touched the ImageCaptionTest file in this commit. Could you please take a look what's wrong?

@malinajirkamalinajirka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM - feel free to merge it when Travis finishes

@planarvoid
planarvoid merged commit 9a41a25 into developOct 31, 2018
@planarvoid
planarvoid deleted the make_aztec_attributes_immutable branch October 31, 2018 13:16
mzorz added a commit that referenced this pull request Nov 6, 2018
…es in case they get modified during listener calls, needed after attributes immutability change in PR #751
@mzorz
mzorz restored the make_aztec_attributes_immutable branch November 7, 2018 20:55
@mzorz
mzorz deleted the make_aztec_attributes_immutable branch November 7, 2018 22:32
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OOB Crash in AztecAttributes setValue/removeAttribute

2 participants

@planarvoid@malinajirka