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

Upgrading incompatible issue #1566

Closed
SElab2019 opened this issue Aug 17, 2019 · 3 comments
Closed

Upgrading incompatible issue #1566

SElab2019 opened this issue Aug 17, 2019 · 3 comments

Comments

@SElab2019
Copy link

Hi,

The following code snippets throw an incompatible issue when I try to upgrade Gson from 2.2.2 to 2.8.5.

public class TestGson {
	
    public static <T> String convertObjectToString(T t, Class<T> clazz) {
        Gson gson = new GsonBuilder().create();
        try {
            return gson.getAdapter(clazz).toJson(t);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}

It works well before, but It throws an error after upgrading:

exception java.io.IOException is never thrown in body of corresponding try statement

Thanks a lot!

@Marcono1234
Copy link
Collaborator

In case this is still relevant, could you please test this with the latest Gson version and also provide a complete code example?

@jvirtanen
Copy link

This actually looks like an improvement in Gson between 2.2.2 and 2.8.5: in Gson 2.8.5, TypeAdapter<T>#toJson(T value) is no longer declared as throwing IOException. This was implemented in 0328479 and released in Gson 2.4.

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Aug 6, 2022

Ah thank you for the clarification, I thought the author of this issue meant the error message occurred during runtime, but it was actually a compiler error.

I guess adding back throws IOException now would not be very useful and would also again break source compatibility. Though the assumption that no IOException can occur is actually incorrect (#2172).

Also, let's better not look at the signature of TypeAdapter.fromJson(String) (fromJson(String) throws IOException) from a consistency perspective 🙈

@Marcono1234 Marcono1234 closed this as not planned Won't fix, can't repro, duplicate, stale Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants