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

ArrayIndexOutOfBoundsException for unclosed dollar quoted string in statement #688

Closed
raderio opened this issue Nov 14, 2016 · 6 comments
Closed
Milestone

Comments

@raderio
Copy link

@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
Copy link
Member

@davecramer davecramer commented Nov 14, 2016

Can we see the code that created that ?

@raderio
Copy link
Author

@raderio raderio commented Nov 14, 2016

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

@vlsi
Copy link
Member

@vlsi 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
Copy link
Member

@davecramer 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
Copy link
Author

@raderio raderio commented Nov 14, 2016

Thank you. I think It's liquibase bug.

@raderio raderio closed this Nov 14, 2016
@vlsi
Copy link
Member

@vlsi 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 ArrayIndexOutOfBoundsException 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
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.