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] Remove invalid marked transient on cacheKey as reported by sonarlint #1084

Merged
merged 2 commits into from
Aug 21, 2017

Conversation

hazendaz
Copy link
Member

@hazendaz hazendaz commented Aug 21, 2017

Test cases written around this to avoid this serious flaw in the future,
configured origin of scanning asking for transient to be added, added
comment about when this would actually fail serialization, and wrote
test for that as well.


Note: revert #989

…onarlint

Test cases written around this to avoid this serious flaw in the future,
configured origin of scanning asking for transient to be added, added
comment about when this would actually fail serialization, and wrote
test for that as well.
@hazendaz hazendaz requested a review from harawata August 21, 2017 20:39
@hazendaz
Copy link
Member Author

#989 issue is invalid given bulk of use-case. The fix actually made things worse. While a real non serializable issue would get that error, the general valid use case will not get null on underlying object list defeating purpose of the class. Test case provided shows both bad case that is not serializable and valid case that is.

@hazendaz
Copy link
Member Author

hang on on this...fixing mistakenly added commit.

@hazendaz
Copy link
Member Author

OK - ready to go.

@hazendaz
Copy link
Member Author

Note: Attempting to make updateList transient again will cause a failure in both unit tests as null pointer exceptions. This is expected behaviour and will prevent accidently doing this in the future.

}

private void canSerialize(final CacheKey object) throws ClassNotFoundException, IOException {
FileOutputStream fout = new FileOutputStream("target/address.ser");
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to use files - ByteArrayOutputStream and ByteArrayInputStream will do just fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Can you show me how to do that and read the data back? I was using ByteArrayOutputStream but then wanted to read it back so changed to files.

Copy link
Contributor

Choose a reason for hiding this comment

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

private static <T> T serialize(T object) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    new ObjectOutputStream(baos).writeObject(object);
 
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    return (T) new ObjectInputStream(bais).readObject();
}

@hazendaz
Copy link
Member Author

@FrantaM Merging now, will look at any comments you have back or re-view later when I have some more time. This for now will get master back in working state for you. Thanks.

@hazendaz hazendaz merged commit 9ffabe2 into mybatis:master Aug 21, 2017
@hazendaz
Copy link
Member Author

hazendaz commented Aug 21, 2017 via email

@kazuki43zoo kazuki43zoo added this to the 3.4.6 milestone Aug 22, 2017
pulllock pushed a commit to pulllock/mybatis-3 that referenced this pull request Oct 19, 2023
[bugfix] Remove invalid marked transient on cacheKey as reported by sonarlint
Sign up for free to 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.

3 participants