Skip to content

Fix string deserialize exception #74

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

Merged
merged 2 commits into from
Dec 16, 2021
Merged

Conversation

tuhuynh27
Copy link
Member

@tuhuynh27 tuhuynh27 commented Dec 14, 2021

Fixes #73

For String byte[], it doesn't follow the java serialization protocol, thus a SerializationException will be thrown when deserializing on String byte[]

@tuhuynh27 tuhuynh27 self-assigned this Dec 14, 2021
@tuhuynh27 tuhuynh27 added the bug Something isn't working label Dec 14, 2021
@tuhuynh27 tuhuynh27 added this to the RC Release milestone Dec 14, 2021
@tuhuynh27 tuhuynh27 linked an issue Dec 14, 2021 that may be closed by this pull request
@@ -115,7 +116,7 @@ public void init() {
} catch (Exception e) {
log.error(e.getMessage(), e);
if (e instanceof InvocationTargetException) {
if (e.getCause() instanceof ClassCastException) {
if (e.getCause() instanceof SerializationException || e.getCause() instanceof ClassCastException) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we wrap the SerializationException thrown during deserilise to a custom one, so that we can distinguish it from the same thrown in call to serialise?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm I didn't get your idea, please suggest changes

Copy link
Member Author

@tuhuynh27 tuhuynh27 Dec 14, 2021

Choose a reason for hiding this comment

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

Like we need to wrap SerializationException and ClassCastException to something like KevaTypeException right?

Copy link
Contributor

@the123saurav the123saurav Dec 14, 2021

Choose a reason for hiding this comment

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

I meant we have code like this:

try {
            byte[] value = chronicleMap.get(key);
            LinkedList<BytesValue> list;
            list = value == null ? new LinkedList<>() : (LinkedList<BytesValue>) SerializationUtils.deserialize(value); <- can throw
            for (byte[] v : values) {
                list.addFirst(new BytesValue(v));
            }
            chronicleMap.put(key, SerializationUtils.serialize(list)); <- can throw
            return list.size();
        } finally {
            lock.unlock();
        }

From 2 places same exception can be thrown but only 1 of them indicates client error.
Although I do agree that serislisation should never throw, but still!

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure @the123saurav, this is a good suggestion. But it will need to add extra code to every operation method, so I think we should create another issue for that refactoring, and put it to the backlog, after the first release we can resume on it

Copy link
Contributor

Choose a reason for hiding this comment

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

SOunds good!

@tuhuynh27
Copy link
Member Author

Hi @the123saurav, created #75 backlog issue for your suggestion

@tuhuynh27 tuhuynh27 merged commit 1af997f into develop Dec 16, 2021
@tuhuynh27 tuhuynh27 deleted the fix/string-deserialize branch December 16, 2021 14:39
@tuhuynh27 tuhuynh27 mentioned this pull request Dec 16, 2021
tuhuynh27 added a commit that referenced this pull request Dec 16, 2021
* fix deserialize string exception

* add wrongtype tests
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.

Do not allow changing type of an existing key
2 participants