@@ -2,6 +2,7 @@ package org.jetbrains.exposed.sql.statements
2
2
3
3
import org.jetbrains.exposed.sql.*
4
4
import org.jetbrains.exposed.sql.statements.api.PreparedStatementApi
5
+ import org.jetbrains.exposed.sql.transactions.TransactionManager
5
6
import org.jetbrains.exposed.sql.vendors.*
6
7
import org.jetbrains.exposed.sql.vendors.inProperCase
7
8
import java.sql.ResultSet
@@ -51,7 +52,7 @@ open class InsertStatement<Key : Any>(
51
52
*/
52
53
fun <T > getOrNull (column : Column <T >): T ? = resultedValues?.firstOrNull()?.getOrNull(column)
53
54
54
- @Suppress(" NestedBlockDepth" , " ComplexMethod" )
55
+ @Suppress(" NestedBlockDepth" , " ComplexMethod" , " TooGenericExceptionCaught " )
55
56
private fun processResults (rs : ResultSet ? , inserted : Int ): List <ResultRow > {
56
57
val autoGeneratedKeys = arrayListOf<MutableMap <Column <* >, Any? >> ()
57
58
@@ -68,9 +69,33 @@ open class InsertStatement<Key : Any>(
68
69
val firstAutoIncColumn = autoIncColumns.firstOrNull { it.autoIncColumnType != null } ? : autoIncColumns.firstOrNull()
69
70
if (firstAutoIncColumn != null || returnedColumns.isNotEmpty()) {
70
71
while (rs?.next() == true ) {
71
- val returnedValues = returnedColumns.associateTo(mutableMapOf ()) { it.first to rs.getObject(it.second) }
72
- if (returnedValues.isEmpty() && firstAutoIncColumn != null ) returnedValues[firstAutoIncColumn] = rs.getObject(1 )
73
- autoGeneratedKeys.add(returnedValues)
72
+ try {
73
+ val returnedValues = returnedColumns.associateTo(mutableMapOf ()) { it.first to rs.getObject(it.second) }
74
+ if (returnedValues.isEmpty() && firstAutoIncColumn != null ) {
75
+ returnedValues[firstAutoIncColumn] = rs.getObject(1 )
76
+ }
77
+ autoGeneratedKeys.add(returnedValues)
78
+ } catch (cause: ArrayIndexOutOfBoundsException ) {
79
+ // EXPOSED-191 Flaky Oracle test on TC build
80
+ // this try/catch should help to get information about the flaky test.
81
+ // try/catch can be safely removed after the fixing the issue.
82
+ // TooGenericExceptionCaught suppress also can be removed
83
+
84
+ val preparedSql = this .prepareSQL(TransactionManager .current(), prepared = true )
85
+
86
+ val returnedColumnsString = returnedColumns
87
+ .mapIndexed { index, pair -> " column: ${pair.first.name} , index: ${pair.second} (columns-list-index: $index )" }
88
+ .joinToString(prefix = " [" , postfix = " ]" , separator = " , " )
89
+
90
+ exposedLogger.error(
91
+ " ArrayIndexOutOfBoundsException on processResults. " +
92
+ " Table: ${table.tableName} , firstAutoIncColumn: ${firstAutoIncColumn?.name} , " +
93
+ " inserted: $inserted , returnedColumnsString: $returnedColumnsString . " +
94
+ " Failed SQL: $preparedSql " ,
95
+ cause
96
+ )
97
+ throw cause
98
+ }
74
99
}
75
100
76
101
if (inserted > 1 && firstAutoIncColumn != null && autoGeneratedKeys.isNotEmpty() && ! currentDialect.supportsMultipleGeneratedKeys) {
0 commit comments