ArrayIndexOutOfBoundsException for unclosed dollar quoted string in statement #688

Closed
raderio opened this Issue Nov 14, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@raderio

raderio commented Nov 14, 2016

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]
@davecramer

This comment has been minimized.

Show comment
Hide comment
@davecramer

davecramer Nov 14, 2016

Member

Can we see the code that created that ?

Member

davecramer commented Nov 14, 2016

Can we see the code that created that ?

@raderio

This comment has been minimized.

Show comment
Hide comment
@raderio

raderio Nov 14, 2016

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

raderio commented Nov 14, 2016

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

@vlsi

This comment has been minimized.

Show comment
Hide comment
@vlsi

vlsi Nov 14, 2016

Member

@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);
    }
  }
Member

vlsi commented Nov 14, 2016

@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);
    }
  }
@davecramer

This comment has been minimized.

Show comment
Hide comment
@davecramer

davecramer Nov 14, 2016

Member

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
.

Member

davecramer commented Nov 14, 2016

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
.

@raderio

This comment has been minimized.

Show comment
Hide comment
@raderio

raderio Nov 14, 2016

Thank you. I think It's liquibase bug.

raderio commented Nov 14, 2016

Thank you. I think It's liquibase bug.

@raderio raderio closed this Nov 14, 2016

@vlsi

This comment has been minimized.

Show comment
Hide comment
@vlsi

vlsi Nov 14, 2016

Member

"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)
Member

vlsi commented Nov 14, 2016

"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)

@vlsi vlsi reopened this Nov 14, 2016

@vlsi vlsi changed the title from ArrayIndexOutOfBoundsException to ArrayIndexOutOfBoundsException for unclosed dollar quoted string in statement Nov 14, 2016

@vlsi vlsi closed this in 8a95d99 Nov 14, 2016

@vlsi vlsi added this to the 9.4.1213 milestone Nov 14, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment