Skip to content

Commit

Permalink
Merge pull request #27343 from Sanne/MSSQL-no-ANTLR
Browse files Browse the repository at this point in the history
Avoid SQL Server JDBC driver to load ANTLR parsers
  • Loading branch information
gsmet authored Aug 18, 2022
2 parents 9381f2e + 52ca34b commit 8e467f5
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 8e467f5

Please sign in to comment.