Skip to content

Commit

Permalink
Avoid SQL Server JDBC driver to load ANTLR parsers
Browse files Browse the repository at this point in the history
In particular we need it to avoid loading ANTLR classes because it's
using versions which are not aligned with our BOM.
Alternatively we could have pursued alignment, but it would need ongoing
maintenance and ANTLR is being used by multiple significant projects.
  • Loading branch information
Sanne committed Aug 17, 2022
1 parent 233f8b8 commit 52ca34b
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import com.microsoft.sqlserver.jdbc.SQLServerException;
import com.microsoft.sqlserver.jdbc.SQLServerStatement;
import com.oracle.svm.core.annotate.AlwaysInline;
import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;

Expand Down Expand Up @@ -60,6 +62,50 @@ static KeyManager[] getKeyManagerFromFile(String certPath, String keyPath, Strin
}
}

@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerLexer")
@Delete //Deleting this one explicitly, so to help with maintenance with the substitutions of SQLServerFMTQuery
final class SQLServerLexerRemove {

}

/**
* This will make sure the ANTLR4 Lexer included in the driver is not reachable; this was mostly
* prevented by not allowing to explicitly set the useFmtOnly connection property, but this code
* path would also get activated on very old SQL Server versions being detected on a connection.
* Since that's not a constant that the compiler can rely on, we need one more substitution.
*/
@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerFMTQuery")
final class SQLServerFMTQuery {

@Substitute
SQLServerFMTQuery(String userSql) throws SQLServerException {
throw new IllegalStateException("It is not supported to connect to SQL Server versions older than 2012");
}

}

/**
* This substitution is not strictly necessary, but it helps by providing a better error message to our users.
*/
@TargetClass(className = "com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement")
final class DisableFMTRemove {

@Substitute
@AlwaysInline("We need this to be constant folded")
public final boolean getUseFmtOnly() throws SQLServerException {
return false;//Important for this to be disabled via a constant
}

@Substitute
public final void setUseFmtOnly(boolean useFmtOnly) throws SQLServerException {
if (useFmtOnly) {
throw new IllegalStateException(
"It is not possible to enable the useFmtOnly option on Quarkus: this option is only useful on SQL Server version 2008 (which is not supported) and introduces several other problems.");
}
}

}

class SQLServerJDBCSubstitutions {

}

0 comments on commit 52ca34b

Please sign in to comment.