-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid recursive enumeration of Class and ClassLoader instances (#364)
Co-authored-by: Aleksandr.Potapov <[email protected]>
- Loading branch information
1 parent
ba0b605
commit 6163a8f
Showing
2 changed files
with
34 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/jvm/test/org/jetbrains/kotlinx/lincheck/ObjectTraverserTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Lincheck | ||
* | ||
* Copyright (C) 2019 - 2024 JetBrains s.r.o. | ||
* | ||
* This Source Code Form is subject to the terms of the | ||
* Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed | ||
* with this file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package org.jetbrains.kotlinx.lincheck | ||
|
||
import org.junit.Assert | ||
import org.junit.Test | ||
|
||
/** | ||
* Checks invariants and restrictions on [enumerateObjects] method. | ||
*/ | ||
class ObjectTraverserTest { | ||
|
||
@Test | ||
fun `should not traverse class and classLoader recursively while enumerating objects`() { | ||
val myObject = @Suppress("unused") object : Any() { | ||
var clazz: Class<*>? = this::class.java | ||
var classLoader: ClassLoader? = this::class.java.classLoader | ||
var integer: Int = 10 | ||
} | ||
val objectEnumeration = enumerateObjects(myObject) | ||
|
||
Assert.assertTrue(objectEnumeration.keys.none { it is Class<*> || it is ClassLoader }) | ||
} | ||
|
||
} |