Skip to content

Commit

Permalink
fix: EXPOSED-714 Fix NullPointerException when non-object Table is de…
Browse files Browse the repository at this point in the history
…fined
  • Loading branch information
PeraSite committed Jan 29, 2025
1 parent e622c7c commit 7b5427e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,5 @@ fun discoverExposedTables(applicationContext: ApplicationContext, excludedPackag
excludedPackages.forEach { provider.addExcludeFilter(RegexPatternTypeFilter(Pattern.compile(it.replace(".", "\\.") + ".*"))) }
val packages = AutoConfigurationPackages.get(applicationContext)
val components = packages.map { provider.findCandidateComponents(it) }.flatten()
return components.map { Class.forName(it.beanClassName).kotlin.objectInstance as Table }
return components.mapNotNull { Class.forName(it.beanClassName).kotlin.objectInstance as? Table }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.jetbrains.exposed.sql.Database
import org.jetbrains.exposed.sql.selectAll
import org.jetbrains.exposed.sql.transactions.transaction
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
Expand All @@ -33,4 +34,12 @@ open class DatabaseInitializerTest {
}
}
}

@Test
fun `ignore non object Table`() {
Database.connect("jdbc:h2:mem:test-spring", user = "sa", driver = "org.h2.Driver")
val tables = discoverExposedTables(applicationContext, listOf())
assertEquals(2, tables.size)
assertArrayEquals(listOf(TestTable, IgnoreTable).toTypedArray(), tables.toTypedArray())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package org.jetbrains.exposed.spring.tables

import org.jetbrains.exposed.sql.Table

open class NonObjectTable : Table()

0 comments on commit 7b5427e

Please sign in to comment.