Skip to content

Commit b19945f

Browse files
authored
[1.20.x] [All] Bug: Inconsistent run in dev environment (#70)
After multiple hours of excruciating pain and mental breakdowns, I have found that `org.reflections` was schizoing about input filters. The fix ? Don't filter anything, just don't.
1 parent 3b30f99 commit b19945f

File tree

3 files changed

+15
-51
lines changed

3 files changed

+15
-51
lines changed

common/src/main/kotlin/com/lambda/command/CommandRegistry.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ object CommandRegistry : Configurable(LambdaConfig), Loadable {
1212
override val name = "command"
1313
val prefix by setting("prefix", ';')
1414

15-
val commands = getInstances<LambdaCommand> {
16-
forPackages("com.lambda.command.commands"); filterInputsBy { it.contains("com.lambda") }
17-
}.toMutableList()
15+
val commands = getInstances<LambdaCommand> { forPackages("com.lambda.command.commands") }.toMutableList()
1816

1917
override fun load(): String {
2018
return "Registered ${commands.size} commands"

common/src/main/kotlin/com/lambda/module/ModuleRegistry.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ import org.reflections.util.ConfigurationBuilder
1010
* The [ModuleRegistry] object is responsible for managing all [Module] instances in the system.
1111
*/
1212
object ModuleRegistry : Loadable {
13-
val modules = getInstances<Module> {
14-
forPackages("com.lambda.module.modules"); filterInputsBy { it.contains("com.lambda") }
15-
}.toMutableList()
13+
val modules = getInstances<Module> { forPackages("com.lambda.module.modules") }.toMutableList()
1614

1715
val moduleNames: Set<String>
1816
get() = modules.map { it.name }.toSet()

common/src/main/kotlin/com/lambda/util/reflections/ReflectionsConfigDsl.kt

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,102 +12,70 @@ annotation class ReflectionsDsl
1212
* A DSL class to configure the Reflections library for runtime scanning.
1313
* This class allows you to specify packages, scanners, URLs, filters, class loaders, and other options
1414
* to build a Reflections configuration.
15+
*
16+
* Important!!
17+
* Be aware that using Reflections can lead to unpredictable and hard-to-debug issues.
18+
* Furthermore, the library we're relying on is outdated and no longer maintained.
19+
* For more reliable methods, refer to Reflections.kt.
1520
*/
1621
@ReflectionsDsl
1722
class ReflectionConfigDsl {
1823
private val packages = mutableListOf<String>()
1924
private val scanners = mutableListOf<Scanners>()
2025
private val urls = mutableListOf<URL>()
21-
private var inputsFilter: (String) -> Boolean = { true }
2226
private val classLoaders = mutableListOf<ClassLoader>()
23-
private var parallel = false
27+
2428
private var shouldExpandSuperTypes = true
2529

2630
/**
2731
* Specifies the packages to be scanned.
2832
*
2933
* @param packages A vararg of package names to be included in the scanning process.
30-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
3134
*/
32-
fun forPackages(vararg packages: String): ReflectionConfigDsl {
35+
fun forPackages(vararg packages: String) {
3336
this.packages += packages
34-
return this
3537
}
3638

3739
/**
3840
* Adds scanners to the configuration.
3941
*
4042
* @param scanners A vararg of [Scanners] to be used for scanning classes, methods, etc.
41-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
4243
*/
43-
fun addScanners(vararg scanners: Scanners): ReflectionConfigDsl {
44+
fun addScanners(vararg scanners: Scanners) {
4445
this.scanners += scanners
45-
return this
4646
}
4747

4848
/**
4949
* Adds URLs to the configuration.
5050
*
5151
* @param urls A vararg of [URL] to be included in the scanning process.
52-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
5352
*/
54-
fun addUrls(vararg urls: URL): ReflectionConfigDsl {
53+
fun addUrls(vararg urls: URL) {
5554
this.urls += urls
56-
return this
57-
}
58-
59-
/**
60-
* Sets a filter for input names.
61-
*
62-
* @param filter A lambda function that takes a [String] and returns a [Boolean], indicating whether the input should be included.
63-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
64-
*/
65-
fun filterInputsBy(filter: (String) -> Boolean): ReflectionConfigDsl {
66-
inputsFilter = filter
67-
return this
6855
}
6956

7057
/**
7158
* Adds class loaders to the configuration.
7259
*
7360
* @param classLoaders A vararg of [ClassLoader] to be used in the scanning process.
74-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
7561
*/
76-
fun addClassLoaders(vararg classLoaders: ClassLoader): ReflectionConfigDsl {
62+
fun addClassLoaders(vararg classLoaders: ClassLoader) {
7763
this.classLoaders += classLoaders
78-
return this
7964
}
8065

8166
/**
82-
* Enables parallel scanning.
83-
*
84-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
67+
* Expand super types during the scan
8568
*/
86-
fun parallel(): ReflectionConfigDsl {
87-
parallel = true
88-
return this
89-
}
90-
91-
/**
92-
* Sets whether to expand super types during scanning.
93-
*
94-
* @param value A [Boolean] indicating whether to expand super types.
95-
* @return The current instance of [ReflectionConfigDsl] for method chaining.
96-
*/
97-
fun expandSuperTypes(value: Boolean): ReflectionConfigDsl {
98-
shouldExpandSuperTypes = value
99-
return this
69+
fun expandSuperTypes(shouldExpand: Boolean) {
70+
shouldExpandSuperTypes = shouldExpand
10071
}
10172

10273
/**
10374
* Builds a [ConfigurationBuilder] based on the current configuration.
104-
*
105-
* @return A [ConfigurationBuilder] configured with the specified packages, scanners, URLs, filters, and class loaders.
10675
*/
10776
fun build(): ConfigurationBuilder = ConfigurationBuilder()
10877
.forPackages(*packages.toTypedArray())
10978
.addUrls(*urls.toTypedArray())
110-
.filterInputsBy(inputsFilter)
11179
.addClassLoaders(*classLoaders.toTypedArray())
11280
.setExpandSuperTypes(shouldExpandSuperTypes)
11381
}

0 commit comments

Comments
 (0)