-
Notifications
You must be signed in to change notification settings - Fork 151
fix: correct ResourceOperationTypeAdapter dispatch and add guard #899
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
fix: correct ResourceOperationTypeAdapter dispatch and add guard #899
Conversation
|
@sebthom Good catch, thank you for the fix! 👍 It is already a great improvement, but would not it even better to check that the (I don't quite like throwing |
|
Would that mean the |
As far as I can see, if (!ResourceOperation.class.isAssignableFrom(type.getRawType())) {
return null;
}with if (!CreateFile.class.isAssignableFrom(type.getRawType()) &&
!DeleteFile.class.isAssignableFrom(type.getRawType()) &&
!RenameFile.class.isAssignableFrom(type.getRawType())) {
return null;
} |
|
This does not work |
|
Thank you for verifying it. Looks like it was not a good idea, then. What do you think about throwing |
I have no strong opinion about this. I am also fine the way it is. |
|
Just looking through the GSON source code, it seems that the |
Does it have any practical relevance which one is thrown? Both are not recoverable or? |
|
It does have a practical relevance by setting a precedent of throwing Otherwise, we could just as well throw a |
|
Maybe this should be discussed separately and addressed in a separate PR? I can see other places where |
|
Thank you for discussing it in detail. The only reason for this discussion is that I could find no prior cases of throwing |
|
I change it to whatever you feel comfortable. Shall I go for IllegalArgumentException? |
|
I'd suggest throwing |
6e38fd4 to
aa32c3e
Compare
|
@pisv done |
- Replace reversed `isAssignableFrom` checks with `instanceof` to correctly handle subclasses (e.g., `CreateFile` derivatives) in write(...) - Add explicit `JsonParseException` for unknown `ResourceOperation` subtypes in write(...) to mirror read(...) and avoid silent malformed JSON - Improves protocol correctness and failure transparency when encountering unsupported operations Tests: add `ResourceOperationTypeAdapterTest` covering subclass serialization and unknown subtype failure
aa32c3e to
86a1073
Compare
|
@sebthom I have made minor updates to |
|
Looks good. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks! 👍 And sorry for the extensive discussion of a small thing that mattered to me.
isAssignableFromchecks withinstanceofto correctly handle subclasses (e.g.,CreateFilederivatives) in write(...)JsonParseExceptionfor unknownResourceOperationsubtypes in write(...) to mirror read(...) and avoid silent malformed JSONTests: add
ResourceOperationTypeAdapterTestcovering subclass serialization and unknown subtype failure