Buggy code:
public class CollationTest extends BaseJDBCTestCase { public CollationTest ( String name ) { } private static final String [ ] NAMES = new String [ ] { "Smith" , "Zebra" , "Ącorn" , "Żebra" , "Acorn" , "Śmith" , "aacorn" } ; public void testDefaultCollation ( ) throws SQLException { } public void testFrenchCollation ( ) throws SQLException { } private void compareAgrave ( Connection conn , int expectedMatchCountForEqual , int expectedMatchCountForLike ) throws SQLException { } public void testPolishCollation ( ) throws SQLException { } public void testNorwayCollation ( ) throws SQLException { } public void testEnglishCollation ( ) throws SQLException { } private void commonTestingForTerritoryBasedDB ( Statement s ) throws SQLException { PreparedStatement ps ; ResultSet rs ; Connection conn = s . getConnection ( ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>APP" ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>1<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>=<seq2seq4repair_space>'CUSTOMER'<seq2seq4repair_space>" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>1<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>CAST<seq2seq4repair_space>" + "<seq2seq4repair_space>(TABLENAME<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(15))<seq2seq4repair_space>=<seq2seq4repair_space>'CUSTOMER'<seq2seq4repair_space>" ) , new String [ ] [ ] { new String [ ] { "1" } } ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>CASE<seq2seq4repair_space>" + "<seq2seq4repair_space>WHEN<seq2seq4repair_space>1=1<seq2seq4repair_space>THEN<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>ELSE<seq2seq4repair_space>'c'<seq2seq4repair_space>END<seq2seq4repair_space>=<seq2seq4repair_space>'SYSCOLUMNS'" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>CAST<seq2seq4repair_space>" + ( "<seq2seq4repair_space>((CASE<seq2seq4repair_space>WHEN<seq2seq4repair_space>1=1<seq2seq4repair_space>THEN<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>ELSE<seq2seq4repair_space>'c'<seq2seq4repair_space>END)<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12))<seq2seq4repair_space>=<seq2seq4repair_space>" + "<seq2seq4repair_space>'SYSCOLUMNS'" ) ) , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>CASE<seq2seq4repair_space>WHEN<seq2seq4repair_space>" + "<seq2seq4repair_space>1=1<seq2seq4repair_space>THEN<seq2seq4repair_space>NAMECHAR<seq2seq4repair_space>ELSE<seq2seq4repair_space>NAME<seq2seq4repair_space>END<seq2seq4repair_space>=<seq2seq4repair_space>NAMECHAR" ) , new String [ ] [ ] { new String [ ] { "7" } } ) ; <START_BUG> checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>CASE<seq2seq4repair_space>" + "<seq2seq4repair_space>WHEN<seq2seq4repair_space>1=1<seq2seq4repair_space>THEN<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>ELSE<seq2seq4repair_space>TABLEID<seq2seq4repair_space>END<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME" ) , new String [ ] [ ] { new String [ ] { "22" } } ) ; <END_BUG> assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>'<seq2seq4repair_space>'<seq2seq4repair_space>=<seq2seq4repair_space>'SYSCOLUMNS<seq2seq4repair_space>'" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + ( "<seq2seq4repair_space>CAST<seq2seq4repair_space>(TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>'<seq2seq4repair_space>'<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12))<seq2seq4repair_space>=<seq2seq4repair_space>" + "<seq2seq4repair_space>'SYSCOLUMNS<seq2seq4repair_space>'" ) ) , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>'<seq2seq4repair_space>'<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>'SYSCOLUMNS<seq2seq4repair_space>'" ) ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>COALESCE(TABLENAME,<seq2seq4repair_space>'c')<seq2seq4repair_space>=<seq2seq4repair_space>'SYSCOLUMNS'" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + ( "<seq2seq4repair_space>CAST<seq2seq4repair_space>(COALESCE<seq2seq4repair_space>(TABLENAME,<seq2seq4repair_space>'c')<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12))<seq2seq4repair_space>=<seq2seq4repair_space>" + "<seq2seq4repair_space>'SYSCOLUMNS'" ) ) , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>NULLIF(TABLENAME,<seq2seq4repair_space>'c')<seq2seq4repair_space>=<seq2seq4repair_space>'SYSCOLUMNS'" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + ( "<seq2seq4repair_space>NULLIF<seq2seq4repair_space>(CAST<seq2seq4repair_space>(TABLENAME<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12)),<seq2seq4repair_space>'c'<seq2seq4repair_space>)<seq2seq4repair_space>=<seq2seq4repair_space>" + "<seq2seq4repair_space>'SYSCOLUMNS'" ) ) , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>SYS" ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>CHAR(ID)<seq2seq4repair_space>FROM<seq2seq4repair_space>APP.CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>CHAR(ID)='0'" ) , new String [ ] [ ] { new String [ ] { "0" } } ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>ID<seq2seq4repair_space>FROM<seq2seq4repair_space>APP.CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>VARCHAR(NAME)='Smith'" ) , new String [ ] [ ] { new String [ ] { "0" } } ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>APP" ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>CHAR(TABLENAME)<seq2seq4repair_space>FROM<seq2seq4repair_space>" + ( "<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>CHAR(TABLENAME)=<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>AND<seq2seq4repair_space>" + "<seq2seq4repair_space>VARCHAR(TABLENAME)<seq2seq4repair_space>=<seq2seq4repair_space>'SYSCOLUMNS'" ) ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>CHAR(TABLENAME)<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + ( "<seq2seq4repair_space>CHAR(TABLENAME)=<seq2seq4repair_space>(CAST<seq2seq4repair_space>(TABLENAME<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12)))<seq2seq4repair_space>AND<seq2seq4repair_space>" + "<seq2seq4repair_space>VARCHAR(TABLENAME)<seq2seq4repair_space>=<seq2seq4repair_space>'SYSCOLUMNS'" ) ) , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "CURRENT_USER<seq2seq4repair_space>=<seq2seq4repair_space>'APP'" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "CAST(CURRENT_USER<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12))<seq2seq4repair_space>=<seq2seq4repair_space>'APP'" ) , new String [ ] [ ] { new String [ ] { "7" } } ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "SESSION_USER<seq2seq4repair_space>=<seq2seq4repair_space>USER" ) , new String [ ] [ ] { new String [ ] { "7" } } ) ; assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "CURRENT<seq2seq4repair_space>ISOLATION<seq2seq4repair_space>=<seq2seq4repair_space>'CS'" ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "CAST(CURRENT<seq2seq4repair_space>ISOLATION<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(12))<seq2seq4repair_space>=<seq2seq4repair_space>'CS'" ) , new String [ ] [ ] { new String [ ] { "7" } } ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>SYS" ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>APP.CUSTOMER<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "CURRENT<seq2seq4repair_space>SCHEMA<seq2seq4repair_space>=<seq2seq4repair_space>'SYS'" ) , new String [ ] [ ] { new String [ ] { "7" } } ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>APP" ) ; if ( XML . classpathMeetsXMLReqs ( ) ) { assertStatementError ( "42818" , s , ( "SELECT<seq2seq4repair_space>XMLSERIALIZE(x<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>" + ( "<seq2seq4repair_space>FROM<seq2seq4repair_space>xmlTable,<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>XMLSERIALIZE(x<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME" ) ) ) ; checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>XMLSERIALIZE(x<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>FROM<seq2seq4repair_space>" + ( "<seq2seq4repair_space>xmlTable,<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>XMLSERIALIZE(x<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>=<seq2seq4repair_space>" + "<seq2seq4repair_space>CAST(TABLENAME<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(10))" ) ) , null ) ; checkPreparedStatementError ( conn , ( "SELECT<seq2seq4repair_space>XMLSERIALIZE(x<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>" + ( "<seq2seq4repair_space>FROM<seq2seq4repair_space>xmlTable,<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>XMLSERIALIZE(?<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME" ) ) , "42Z70" ) ; checkPreparedStatementError ( conn , ( "SELECT<seq2seq4repair_space>XMLSERIALIZE(x<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>FROM<seq2seq4repair_space>" + ( "<seq2seq4repair_space>xmlTable,<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>XMLSERIALIZE(?<seq2seq4repair_space>as<seq2seq4repair_space>CHAR(10))<seq2seq4repair_space>=<seq2seq4repair_space>" + "<seq2seq4repair_space>CAST(TABLENAME<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(10))" ) ) , "42Z70" ) ; } s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>APP" ) ; s . executeUpdate ( ( "CREATE<seq2seq4repair_space>FUNCTION<seq2seq4repair_space>CONCAT_NOCALL(VARCHAR(10),<seq2seq4repair_space>VARCHAR(10))<seq2seq4repair_space>" + ( ( "<seq2seq4repair_space>RETURNS<seq2seq4repair_space>VARCHAR(20)<seq2seq4repair_space>RETURNS<seq2seq4repair_space>NULL<seq2seq4repair_space>ON<seq2seq4repair_space>NULL<seq2seq4repair_space>INPUT<seq2seq4repair_space>EXTERNAL<seq2seq4repair_space>NAME<seq2seq4repair_space>" + "'org.apache.derbyTesting.functionTests.tests.lang.RoutineTest.concat'<seq2seq4repair_space>" ) + "<seq2seq4repair_space>LANGUAGE<seq2seq4repair_space>JAVA<seq2seq4repair_space>PARAMETER<seq2seq4repair_space>STYLE<seq2seq4repair_space>JAVA" ) ) ) ; s . executeUpdate ( ( "CREATE<seq2seq4repair_space>FUNCTION<seq2seq4repair_space>AA.B()<seq2seq4repair_space>RETURNS<seq2seq4repair_space>VARCHAR(10)<seq2seq4repair_space>NO<seq2seq4repair_space>SQL<seq2seq4repair_space>" + "PARAMETER<seq2seq4repair_space>STYLE<seq2seq4repair_space>JAVA<seq2seq4repair_space>LANGUAGE<seq2seq4repair_space>JAVA<seq2seq4repair_space>EXTERNAL<seq2seq4repair_space>NAME<seq2seq4repair_space>'aaa.bbb.ccc'<seq2seq4repair_space>" ) ) ; assertStatementError ( "XJ001" , s , "SELECT<seq2seq4repair_space>AA.B()<seq2seq4repair_space>FROM<seq2seq4repair_space>CUSTOMER<seq2seq4repair_space>" ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>APP" ) ; ps = conn . prepareStatement ( ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>?<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME" ) ) ; ps . setString ( 1 , "SYSCOLUMNS" ) ; rs = ps . executeQuery ( ) ; JDBC . assertFullResultSet ( rs , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; checkPreparedStatementError ( conn , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>SUBSTR(?,2)<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME" ) , "42818" ) ; ps = conn . prepareStatement ( ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>SUBSTR(?,2)<seq2seq4repair_space>=<seq2seq4repair_space>CAST(TABLENAME<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(10))" ) ) ; ps . setString ( 1 , "aSYSCOLUMNS" ) ; rs = ps . executeQuery ( ) ; JDBC . assertFullResultSet ( rs , new String [ ] [ ] { new String [ ] { "SYSCOLUMNS" } } ) ; checkPreparedStatementError ( conn , ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>" + "<seq2seq4repair_space>WHERE<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>?<seq2seq4repair_space>LIKE<seq2seq4repair_space>'SYSCOLUMNS<seq2seq4repair_space>'" ) , "42ZA2" ) ; ps = conn . prepareStatement ( ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>" + "<seq2seq4repair_space>CAST((TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>?)<seq2seq4repair_space>AS<seq2seq4repair_space>CHAR(20))<seq2seq4repair_space>LIKE<seq2seq4repair_space>'SYSCOLUMNS'" ) ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>SYS" ) ; ps = conn . prepareStatement ( ( "SELECT<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>" + "<seq2seq4repair_space>WHERE<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>||<seq2seq4repair_space>?<seq2seq4repair_space>LIKE<seq2seq4repair_space>'SYSCOLUMNS'" ) ) ; s . executeUpdate ( "set<seq2seq4repair_space>schema<seq2seq4repair_space>APP" ) ;

Fix:
checkLangBasedQuery ( s , ( "SELECT<seq2seq4repair_space>count(*)<seq2seq4repair_space>FROM<seq2seq4repair_space>SYS.SYSTABLES<seq2seq4repair_space>WHERE<seq2seq4repair_space>CASE<seq2seq4repair_space>" + "<seq2seq4repair_space>WHEN<seq2seq4repair_space>1=1<seq2seq4repair_space>THEN<seq2seq4repair_space>TABLENAME<seq2seq4repair_space>ELSE<seq2seq4repair_space>TABLEID<seq2seq4repair_space>END<seq2seq4repair_space>=<seq2seq4repair_space>TABLENAME" ) , new String [ ] [ ] { new String [ ] { "23" } } ) ;