Hi,
I get an exception with a strange "C:/test outside C:/" message, when:
- Opening a database with implicit relative path name
- While h2.baseDir is set to the root of a Windows drive ("C:/" or "C:\\")
However, it works as expected with h2.baseDir="C:/anything".
Example code:
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class H2BaseDirProblem
{
public static void main(String[] args)
throws SQLException
{
Connection conn;
// Works:
System.setProperty("h2.baseDir", "C:/anything");
conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
// Fails with any of these:
System.setProperty("h2.baseDir", "C:/");
conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
System.setProperty("h2.baseDir", "C:\\");
conn = DriverManager.getConnection("jdbc:h2:test", "sa", "");
conn.close();
}
}
It throws the following exception:
Exception in thread "main" org.h2.jdbc.JdbcSQLException: IO Exception:
"C:/test outside C:/" [90028-174]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:332)
at org.h2.message.DbException.get(DbException.java:172)
at org.h2.message.DbException.get(DbException.java:149)
at org.h2.engine.ConnectionInfo.setBaseDir(ConnectionInfo.java:192)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:101)
at org.h2.jdbc.JdbcConnection.<init>(JdbcConnection.java:90)
at org.h2.Driver.connect(Driver.java:73)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at H2BaseDirProblem.main(H2BaseDirProblem.java:20)
Is this the expected behaviour?
Based on the strange error message (well, C:/test is not outside C:/) I
have a feeling that an internal check doesn't work the way it was
originally intended.
I am using h2-1.3.174.jar on Windows7, JRE6.
Hint to localize the problem:
>From the exception message I guess the value of absDir was "C:/".
I guess the trailing '/' is unexpected in the condition check in the
following statement:
org.h2.engine.ConnectionInfo.setBaseDir(ConnectionInfo.java:188)
if (normalizedName.charAt(absDir.length()) != '/') {
// database must be within the directory
// (with baseDir=/test, the database name must not be
// /test2/x and not /test2)
throw DbException.get(ErrorCode.IO_EXCEPTION_1,
normalizedName + " outside " +
absDir);
}
A different, maybe related case:
It also throws an exception with h2.baseDir="C:" (without slash or
backslash).
The message in that case is: "C:/test outside
C:/<current/working/directory/on/C>".
The error message is correct by itself (it is actually outside).
However, I do not understand why the relative DB path was interpreted
literally at "C:", while the baseDir became "
C:/<current/working/directory/on/C>".
Is that the intended behaviour?
ps: The case with "C:" is not really important, just noted - my real
trouble was with "C:/"
Thanks,
--
Bartók István
--
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.