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

org.postgresql.util.PGobject is in unnamed module of loader 'app' #2366

Open
dirkluijk opened this issue Dec 15, 2021 · 3 comments
Open

org.postgresql.util.PGobject is in unnamed module of loader 'app' #2366

dirkluijk opened this issue Dec 15, 2021 · 3 comments

Comments

@dirkluijk
Copy link

Please read https://stackoverflow.com/help/minimal-reproducible-example

Describe the issue
A clear and concise description of what the issue is.

Driver Version?
42.2.23 and 42.2.24

Java Version?
openjdk 15.0.1

OS Version?
Mac OS

PostgreSQL Version?
Postgres 10

Since version 42.2.23 we get this error:

java.lang.ClassCastException: class java.lang.String cannot be cast to class org.postgresql.util.PGobject (java.lang.String is in module java.base of loader 'bootstrap'; org.postgresql.util.PGobject is in unnamed module of loader 'app')

maybe it's related to
#2153 or #1949 (not sure though)

Any ideas?

@davecramer
Copy link
Member

Do you have the rest of the exception. I'd like to see what happens before this is thrown.

@dirkluijk
Copy link
Author

dirkluijk commented Dec 15, 2021

I checked, the code was was doing something like this:

Object[] values =  (Object[]) resultSet.getArray("some-field").getArray();
String firstValue = ((PGobject) values[0]).getValue()

I changed it to:

Object[] values = (Object[]) resultSet.getArray("some-field").getArray();
String firstValue = (String) values[0];

which can be simplified to:

String[] values = (String[]) resultSet.getArray("some-field").getArray();
String firstValue = values[0];

That fixed it. Which is fine for us, but maybe good to know that it was a breaking change.

@dirkluijk
Copy link
Author

dirkluijk commented Dec 15, 2021

It seems to affect enum arrays. I looks like it's now automatically returned like an array of strings instead of a PGobject (which is actually an improvement imho). 😄

before:

Map<String, Object> actionDefault = template.queryForMap("SELECT * FROM ...");
assertThat(actionDefault).containsEntry("action", create("someType", "SOME_VALUE"));

private static PGobject create(String type, String value) {
    PGobject pGobject = new PGobject();
    pGobject.setType(type);
    try {
        pGobject.setValue(value);
    } catch (SQLException e) {
        throw new IllegalArgumentException(e);
    }
    return pGobject;
}

after:

Map<String, Object> actionDefault = template.queryForMap("SELECT * FROM ...");
assertThat(actionDefault).containsEntry("action", "SOME_VALUE");

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

No branches or pull requests

2 participants