Bug #25210 JConnector thorows NPE
Submitted: 20 Dec 2006 11:36 Modified: 11 Nov 2009 2:37
Reporter: Valery Gorbunov Email Updates:
Status: Won't fix Impact on me:
None 
Category:Connector / J Severity:S3 (Non-critical)
Version:5.0.4 OS:Windows (Windows 2003)
Assigned to: CPU Architecture:Any

[20 Dec 2006 11:36] Valery Gorbunov
Description:
see stack
java.lang.NullPointerException
	at com.mysql.jdbc.ResultSetMetaData.getField(ResultSetMetaData.java:397)
	at com.mysql.jdbc.ResultSetMetaData.getColumnType(ResultSetMetaData.java:275)
	at com.mysql.jdbc.MysqlParameterMetadata.getParameterType(MysqlParameterMetadata.java:80)
	at com.intalio.bpms.connector.jdbc.core.parameter.ParametersHelper.newParameters(ParametersHelper.java:211)
	at com.intalio.bpms.connector.jdbc.vc.editors.SQLMultiPageEditorContributor$2.run(SQLMultiPageEditorContributor.java:223)
	at org.eclipse.jface.action.Action.runWithEvent(Action.java:499)
	at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:539)
	at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:488)
	at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:441)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:928)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3348)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2968)
	at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:1914)
	at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:1878)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:419)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
	at org.eclipse.ui.internal.ide.IDEApplication.run(IDEApplication.java:95)
	at org.eclipse.core.internal.runtime.PlatformActivator$1.run(PlatformActivator.java:78)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:92)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:68)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:400)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:177)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)

How to repeat:
Create table:

create table TEST.SIMPLE_TYPES  (
   INTEGER_COLUMN       INTEGER,
   DOUBLE_COLUMN        FLOAT(12),
   BOOLEAN_COLUMN       SMALLINT,
   VARCHAR_COLUMN       VARCHAR(255),
   LONG_VARCHAR_COLUMN TEXT,
   BINARY_COLUMN        BLOB,
   DECIMAL_COLUMN       NUMERIC(15,2),
   DATE_COLUMN          DATE,
   TIME_COLUMN          TIME,
   TIMESTAMP_COLUMN     TIMESTAMP
)

run  test:

public void testMySQLBug() throws SQLException{
	Connection connection = TestHelper.getMySqlDataSource().getConnection();
	String query = "SELECT  * FROM test.simple_types\n" + 
	"WHERE (5 = n)\n" + // n is undefined variable 
	"#-- timestamp_column = ?\n" + 
	"#--               AND  date_column = ?\n" + 
	"#--                AND  time_column = ?\n" +
	"#--                AND  decimal_column = ?\n" +
	"#--                AND  double_column = ? \n" +
	"#--                AND  varchar_column = ?\n" +
	"#--) OR 1=1\n";
	PreparedStatement st = connection.prepareStatement(query);
	ParameterMetaData md = st.getParameterMetaData();
	int c = md.getParameterCount();
	//assertEquals(0,c);  // c == 6 but should be 0
	for (int i = 1; i <= c; i++) {
		try {
			md.getParameterType( i );
		} catch (RuntimeException e) {
		
			e.printStackTrace();
		}
	}
	}
[20 Dec 2006 11:36] Valery Gorbunov
SQL query for test not correct MySQL should  throw syntax exception while statement preparation or something similar or report zerro parameters.
I think not correct SQL parameter parser.
[10 Jan 2007 18:29] Mark Matthews
We have a chicken and egg situation here. Connector/J uses syntax error returned by server to determine that it's not possible to prepare a statement.

Unfortunately, _real_ syntax error, and "not-preparable" have the same error code.

The driver doesn't have a full SQL parser in it (that would be wasteful) when it emulates statements, it just knows about identifier and literal quoting and looks for '?' placeholders.

The real fix would be either for the server to allow preparing of all statements, or to return a different error code for "not-preparable".
[10 Apr 2007 13:25] Valeriy Kravchuk
So, I think, "to be fixed later" is a more proper state for this bug.