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

PgRow pgColumns index order different from actual indexes (caused by relying on HashMap.values() order) #58

Open
ratamaa opened this issue Dec 11, 2017 · 0 comments

Comments

@ratamaa
Copy link

ratamaa commented Dec 11, 2017

In: https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/impl/PgRow.java#L47
PgColumn[] pgColumns order might be different from PgColumn.index values which makes get...(int index) methods quite useless at the moment.

See example situation in debugger:
screen shot 2017-12-11 at 22 09 12

Unfortunately this issue can most likely re-produce by random, so I can not provide a particular test case that would always fail.

This is caused by relying on HashMap.values() order although the order is not the same as the order they are put into the Map by its contract. This issue could most likely be resolved by using LinkedHashMap in com.github.pgasync.impl.PgConnection#getColumns:
https://github.com/alaisi/postgres-async-driver/blob/master/src/main/java/com/github/pgasync/impl/PgConnection.java#L187

However, the parameter is of of Map interface type which means, one can not assume anything about the implementation. Therefore, more appropriate fix could be e.g. in the constructor of PgRow:

    pgColumns = new PgColumn[row.getColumns().size()];
    for (PgColumn col : row.getColumns().values()) {
        pgColumns[col.index] = col;
    }
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

1 participant