Skip to content

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

@ratamaa

Description

@ratamaa

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;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions