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

NPE when unable to init the driver #107

Closed
arina-ielchiieva opened this issue Aug 14, 2018 · 5 comments
Closed

NPE when unable to init the driver #107

arina-ielchiieva opened this issue Aug 14, 2018 · 5 comments

Comments

@arina-ielchiieva
Copy link
Collaborator

Command:
/usr/lib/jvm/java-1.8.0-openjdk/bin/java -cp ... sqlline.SqlLine -d org.apache.drill.jdbc.Dri --maxWidth=10000

org.apache.drill.jdbc.Dri
java.lang.NullPointerException
sqlline version 1.5.0-SNAPSHOT
0: jdbc:drill:zk=local> !quit
java.lang.ClassNotFoundException: org.apache.drill.jdbc.Dri
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	at java.lang.Class.forName0(Native Method)
	at java.lang.Class.forName(Class.java:264)
	at sqlline.DatabaseConnection.connect(DatabaseConnection.java:114)
	at sqlline.DatabaseConnection.getConnection(DatabaseConnection.java:204)
	at sqlline.Commands.close(Commands.java:920)
	at sqlline.Commands.quit(Commands.java:877)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at sqlline.ReflectiveCommandHandler.execute(ReflectiveCommandHandler.java:38)
	at sqlline.SqlLine.dispatch(SqlLine.java:806)
	at sqlline.SqlLine.begin(SqlLine.java:683)
	at sqlline.SqlLine.start(SqlLine.java:374)
	at sqlline.SqlLine.main(SqlLine.java:266)
Connection is already closed.

Sqlline displays the incorrect driver class name with NPE afterwards. Does not fail and only after issuing quit command, displays full error message.
Actually, not quite sure why sqlline does not fail completely if passed driver is incorrect.

@snuyanzin
Copy link
Collaborator

snuyanzin commented Aug 14, 2018

Was not able to reproduce NPE
However was able to reproduce issue related to fail in exit. It also appears right after !connect command which I do not see in your example. How do you initialize connect?
The reason is that on !quit close method tries to close connections getting from getConnection. At the same time getConnection returns existing or initiates a new one if there is no existing and that is strange if we are talking about close method. So I have such a trace twice: first after !connect, second after !close

@arina-ielchiieva
Copy link
Collaborator Author

@snuyanzin what errors do you get when you pass incorrect driver name (ex: -d incorrect_name)? Because I see the NPE on the latest master as well. It occurs when setComplections are called (https://github.com/julianhyde/sqlline/blob/master/src/main/java/sqlline/Commands.java#L1110).

@snuyanzin
Copy link
Collaborator

Yes, sorry, my fault
the test to reproduce NPE
sqlline.SqlLineArgsTest

@Test
public void testTablesH2WithErrorDriver() throws Throwable {
    connectionSpec = ConnectionSpec.ERROR_H2_DRIVER;
    final String script = "!tables\n";

    checkScriptFile(script, true, equalTo(SqlLine.Status.OK),
        not(containsString("NullPointerException")));
}
...
public static final ConnectionSpec ERROR_H2_DRIVER =
        new ConnectionSpec("jdbc:h2:mem:", "sa", "", "ERROR_DRIVER");

@julianhyde
Copy link
Owner

Fixed in 9b0f7b8.

@arina-ielchiieva
Copy link
Collaborator Author

Verified:

Could not find driver org.apache.drill.jdbc.Dri; using registered driver org.apache.drill.jdbc.Driver instead
Aug 26, 2018 2:07:51 PM org.glassfish.jersey.server.ApplicationHandler initialize
INFO: Initiating Jersey application, version Jersey: 2.8 2014-04-29 01:25:26...
sqlline version 1.5.0-SNAPSHOT
0: jdbc:drill:zk=local> !quit
Closing: org.apache.drill.jdbc.impl.DrillConnectionImpl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants