pgjdbc / pgjdbc

Postgresql JDBC Driver

Home Page:http://jdbc.postgresql.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ArrayIndexOutOfBoundsException for unclosed dollar quoted string in statement

raderio opened this issue · comments

commented

CREATE OR REPLACE FUNCTION update_on_change() RETURNS TRIGGER AS $$
BEGIN
NEW.updated_at = NOW();
RETURN NEW;
END;
$$ language 'plpgsql';


 java.lang.ArrayIndexOutOfBoundsException: null
        at java.lang.System.arraycopy(Native Method) ~[na:1.8.0_111]
        at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:597) ~[na:1.8.0_111]
        at java.lang.StringBuilder.append(StringBuilder.java:190) ~[na:1.8.0_111]
        at org.postgresql.core.Parser.parseSql(Parser.java:1020) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
        at org.postgresql.core.Parser.replaceProcessing(Parser.java:972) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
        at org.postgresql.core.CachedQueryCreateAction.create(CachedQueryCreateAction.java:40) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
        at org.postgresql.core.QueryExecutorBase.createQueryByKey(QueryExecutorBase.java:309) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]
        at org.postgresql.core.QueryExecutorBase.createQuery(QueryExecutorBase.java:320) ~[postgresql-9.4.1212.jre7.jar:9.4.1212.jre7]

Can we see the code that created that ?

commented

Well, it's liquibase migration. So, I don't have code.

@raderio , can you provide more details?
Is the issue reproducible every time?

ArrayIndexOutOfBoundsException: null looks like a JIT compiler bug

In the mean time, this passes for me with Oracle jdk1.8.0_102

public class StatementTest ... {
...
  public void testPlpgsql() throws SQLException {
    String str = "CREATE OR REPLACE FUNCTION update_on_change() RETURNS TRIGGER AS $$\n"
        + "BEGIN\n"
        + "NEW.updated_at = NOW();\n"
        + "RETURN NEW;\n"
        + "END;\n"
        + "$$ language 'plpgsql';";

    PreparedStatement ps = null;
    try {
      ps = con.prepareStatement(str);
      System.out.println("ps.executeUpdate() = " + ps.executeUpdate());
    } finally {
      TestUtil.closeQuietly(ps);
    }
  }

as does this for me:

Connection con =
DriverManager.getConnection("jdbc:postgresql://localhost/test",
"test", "");
con.createStatement().execute("CREATE OR REPLACE FUNCTION
update_on_change() RETURNS TRIGGER AS $$\n" +
"BEGIN\n" +
"NEW.updated_at = NOW();\n" +
"RETURN NEW;\n" +
"END;\n" +
"$$ language 'plpgsql';\n" +
"\n");

con.prepareStatement("CREATE OR REPLACE FUNCTION update_on_change()
RETURNS TRIGGER AS $$\n" +
"BEGIN\n" +
"NEW.updated_at = NOW();\n" +
"RETURN NEW;\n" +
"END;\n" +
"$$ language 'plpgsql';\n" +
"\n").execute();

Dave Cramer

On 14 November 2016 at 08:55, Vladimir Sitnikov notifications@github.com
wrote:

@raderio https://github.com/raderio , can you provide more details?
Is the issue reproducible every time?

ArrayIndexOutOfBoundsException: null looks like a JIT compiler bug

In the mean time, this passes for me with Oracle jdk1.8.0_102

public class StatementTest ... {...
public void testPlpgsql() throws SQLException {
String str = "CREATE OR REPLACE FUNCTION update_on_change() RETURNS TRIGGER AS $$\n"
+ "BEGIN\n"
+ "NEW.updated_at = NOW();\n"
+ "RETURN NEW;\n"
+ "END;\n"
+ "$$ language 'plpgsql';";

PreparedStatement ps = null;
try {
  ps = con.prepareStatement(str);
  System.out.println("ps.executeUpdate() = " + ps.executeUpdate());
} finally {
  TestUtil.closeQuietly(ps);
}

}


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
#688 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAYz9hNX2mYly61LVGetPpqPagDYnz0Kks5q-GhFgaJpZM4KxUkR
.

commented

Thank you. I think It's liquibase bug.

"Unterminated dollar quote" leads to ArrayIndexOutOfBoundsException.
I think it makes sense to have proper error messages for that at pgjdbc level.

  public void testPlpgsql() throws SQLException {
    String str = "CREATE OR REPLACE FUNCTION update_on_change() RETURNS TRIGGER AS $$\n"
        + "BEGIN\n"
        + "NEW.updated_at = NOW();\n"
        + "RETURN NEW;\n"
        + "END;";

    PreparedStatement ps = null;
    try {
      ps = con.prepareStatement(str);
      System.out.println("ps.executeUpdate() = " + ps.executeUpdate());
    } finally {
      TestUtil.closeQuietly(ps);
    }
  }
java.lang.ArrayIndexOutOfBoundsException
    at java.lang.System.arraycopy(Native Method)
    at java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:597)
    at java.lang.StringBuilder.append(StringBuilder.java:190)
    at org.postgresql.core.Parser.parseSql(Parser.java:1021)
    at org.postgresql.core.Parser.replaceProcessing(Parser.java:973)
    at org.postgresql.core.CachedQueryCreateAction.create(CachedQueryCreateAction.java:41)
    at org.postgresql.core.CachedQueryCreateAction.create(CachedQueryCreateAction.java:17)
    at org.postgresql.util.LruCache.borrow(LruCache.java:115)
    at org.postgresql.core.QueryExecutorBase.borrowQuery(QueryExecutorBase.java:266)
    at org.postgresql.jdbc.PgConnection.borrowQuery(PgConnection.java:141)
    at org.postgresql.jdbc.PgPreparedStatement.<init>(PgPreparedStatement.java:88)
    at org.postgresql.jdbc.PgConnection.prepareStatement(PgConnection.java:1191)