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

NPE in MapArguments - using bindFromMap with one of values null #92

Closed
silvpol opened this issue Feb 15, 2014 · 0 comments · Fixed by #94
Closed

NPE in MapArguments - using bindFromMap with one of values null #92

silvpol opened this issue Feb 15, 2014 · 0 comments · Fixed by #94

Comments

@silvpol
Copy link

silvpol commented Feb 15, 2014

As per title, using bindFromMap with any values being null causes NPE. I have written a simple test case for this. Not sure if this is relevant, but I'm using PostgreSQL.
Test fails in MapArguments in find() on line 44. If value for given entry is null, this bit

return foreman.waffle(args.get(name).getClass(), args.get(name), ctx);

causes NPE.

import java.util.HashMap;

import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.postgresql.ds.PGSimpleDataSource;
import org.skife.jdbi.v2.DBI;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.HashPrefixStatementRewriter;
import org.skife.jdbi.v2.Update;

public class JDBI_Tests {

    static Handle dbHandle;

    @BeforeClass
    public static void prepare() {
        PGSimpleDataSource ds = new PGSimpleDataSource();
        ds.setDatabaseName("testdb");
        ds.setUser("testuser");
        ds.setPassword("testpassword");
        ds.setServerName("localhost");

        DBI dbi = new DBI(ds);
        dbHandle = dbi.open();
    }

    @AfterClass
    public static void cleanup() {
        dbHandle.close();
    }

    @Test
    public void MapArguments_NPE() {
        HashMap<String, Object> params = new HashMap<>(1);
        params.put("colA", null);
        Update insert = dbHandle.createStatement("INSERT INTO test (colA) values (#colA)");
        insert.setStatementRewriter(new HashPrefixStatementRewriter());
        insert.bindFromMap(params);
        insert.execute();
    }

}
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
stevenschlansker pushed a commit to stevenschlansker/jdbi that referenced this issue Mar 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant