Skip to content

Commit

Permalink
Fix for Bug#101558 (32141210), NULLPOINTEREXCEPTION WHEN EXECUTING
Browse files Browse the repository at this point in the history
INVALID QUERY WITH USEUSAGEADVISOR ENABLED.
  • Loading branch information
soklakov authored and fjssilva committed Feb 10, 2021
1 parent 5622bc0 commit d11cb2f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Version 8.0.24

- Fix for Bug#101558 (32141210), NULLPOINTEREXCEPTION WHEN EXECUTING INVALID QUERY WITH USEUSAGEADVISOR ENABLED.

- Fix for Bug#102076 (32329915), CONTRIBUTION: MYSQL JDBC DRIVER RESULTSET.GETLONG() THROWS NUMBEROUTOFRANGE.

- Fix for Bug#31747910, BUG 30474158 FIX IMPROVES JDBC COMPLIANCE BUT CHANGES DEFAULT RESULTSETTYPE HANDLING.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -1301,7 +1301,8 @@ public void realClose(boolean calledExplicitly, boolean closeOpenResults) throws
}

if (this.useUsageAdvisor) {
if (((PreparedQuery<?>) this.query).getQueryBindings().getNumberOfExecutions() <= 1) {
QueryBindings<?> qb = ((PreparedQuery<?>) this.query).getQueryBindings();
if (qb == null || qb.getNumberOfExecutions() <= 1) {
this.session.getProfilerEventHandler().processEvent(ProfilerEvent.TYPE_USAGE, this.session, this, null, 0, new Throwable(),
Messages.getString("PreparedStatement.43"));
}
Expand Down
28 changes: 27 additions & 1 deletion src/test/java/testsuite/regression/StatementRegressionTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates.
* Copyright (c) 2002, 2021, Oracle and/or its affiliates.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 2.0, as published by the
Expand Down Expand Up @@ -11385,4 +11385,30 @@ public void testBug101413() throws Exception {
}
}
}

/**
* Tests fix for Bug#101558 (32141210), NULLPOINTEREXCEPTION WHEN EXECUTING INVALID QUERY WITH USEUSAGEADVISOR ENABLED.
*
* @throws Exception
*/
@Test
public void testBug101558() throws Exception {

Properties props = new Properties();
props.setProperty(PropertyKey.cachePrepStmts.getKeyName(), "true");
props.setProperty(PropertyKey.useServerPrepStmts.getKeyName(), "true");
props.setProperty(PropertyKey.useUsageAdvisor.getKeyName(), "true");
Connection testConn = getConnectionWithProps(props);

// The query would work after setting allowMultiQueries=true, but when it is set the original bug is not reproducible.
assertThrows(SQLException.class,
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SELECT 1 FROM DUAL' at line 1",
() -> {
PreparedStatement statement = testConn.prepareStatement("SELECT 1 FROM DUAL; SELECT 1 FROM DUAL");
statement.execute();
return null;
});

testConn.close();
}
}

0 comments on commit d11cb2f

Please sign in to comment.