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

JsonWriter.name does not throw exception when not inside JSON object #2407

Closed
Marcono1234 opened this issue Jun 4, 2023 · 5 comments · Fixed by #2476
Closed

JsonWriter.name does not throw exception when not inside JSON object #2407

Marcono1234 opened this issue Jun 4, 2023 · 5 comments · Fixed by #2476
Labels

Comments

@Marcono1234
Copy link
Collaborator

Gson version

2.10.1

Java / Android version

Java 17

Description

Calling JsonWriter.name (and maybe also JsonTreeWriter.name) when not inside a JSON object does not fail.

Expected behavior

An IllegalStateException should be thrown

Actual behavior

No exception is thrown

Reproduction steps

JsonWriter jsonWriter = new JsonWriter(new StringWriter());
// Should throw exception
jsonWriter.name("a");
@Marcono1234 Marcono1234 added the bug label Jun 4, 2023
@eamonnmcmanus
Copy link
Member

Seems like we should fix this. You will get an exception if you write pretty much anything else after the .name, but it would be better to get it exactly at the point where the mistake was made.

@shivam-sehgal
Copy link
Contributor

Hi, just wanted to ask, if anyone not working on this, would like to contribute on this issue

@Marcono1234
Copy link
Collaborator Author

@shivam-sehgal, thanks for asking! To my knowledge no one is working on this yet. Though before you start, please have a look at the contributing guide and also at the pull request checklist.

@shivam-sehgal
Copy link
Contributor

@shivam-sehgal, thanks for asking! To my knowledge no one is working on this yet. Though before you start, please have a look at the contributing guide and also at the pull request checklist.

Thanks @Marcono1234 , for letting me know the status of the bug, and the docs, have done the needful by signing the CLA and going through the PR checklist, and will look into this issue.

@shivam-sehgal
Copy link
Contributor

Hello @Marcono1234,
I wanted to inform you that I've submitted a Pull Request addressing this issue. Your valuable feedback would be greatly appreciated.
Thank you!

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