@@ -23,7 +23,6 @@ import java.lang.instrument.UnmodifiableClassException
2323import java.util.*
2424import java.util.concurrent.ConcurrentHashMap
2525import java.util.function.BiConsumer
26- import java.util.function.Consumer
2726import java.util.stream.Collectors
2827
2928object LiveInstrumentService {
@@ -42,26 +41,21 @@ object LiveInstrumentService {
4241 timer.schedule(object : TimerTask () {
4342 override fun run () {
4443 val removeInstruments: MutableList <ActiveLiveInstrument > = ArrayList ()
45- instruments.values.forEach( Consumer {
44+ instruments.values.forEach {
4645 if (it.instrument.expiresAt != null
4746 && System .currentTimeMillis() >= it.instrument.expiresAt!!
4847 ) {
4948 removeInstruments.add(it)
5049 }
51- })
52- applyingInstruments.values.forEach( Consumer {
50+ }
51+ applyingInstruments.values.forEach {
5352 if (it.instrument.expiresAt != null
5453 && System .currentTimeMillis() >= it.instrument.expiresAt!!
5554 ) {
5655 removeInstruments.add(it)
5756 }
58- })
59- removeInstruments.forEach(Consumer {
60- _removeInstrument (
61- it.instrument,
62- null
63- )
64- })
57+ }
58+ removeInstruments.forEach { _removeInstrument (it.instrument, null ) }
6559 }
6660 }, 5000 , 5000 )
6761 }
@@ -212,6 +206,7 @@ object LiveInstrumentService {
212206 removedInstrument.isRemoval = true
213207 if (removedInstrument.isLive) {
214208 liveInstrumentApplier.apply (instrumentation!! , removedInstrument)
209+ removedInstrument.instrument.id?.let { ContextReceiver .clear(it) }
215210 return listOf (ModelSerializer .INSTANCE .toJson(removedInstrument.instrument))
216211 }
217212 }
@@ -223,6 +218,7 @@ object LiveInstrumentService {
223218 removedInstrument.isRemoval = true
224219 if (removedInstrument.isLive) {
225220 liveInstrumentApplier.apply (instrumentation!! , removedInstrument)
221+ removedInstrument.instrument.id?.let { ContextReceiver .clear(it) }
226222 removedInstruments.add(ModelSerializer .INSTANCE .toJson(removedInstrument.instrument))
227223 }
228224 }
@@ -232,8 +228,8 @@ object LiveInstrumentService {
232228 return emptyList()
233229 }
234230
235- fun _removeInstrument (instrument : LiveInstrument ? , ex : Throwable ? ) {
236- removeInstrument(instrument!! .location.source, instrument.location.line, instrument.id)
231+ fun _removeInstrument (instrument : LiveInstrument , ex : Throwable ? ) {
232+ removeInstrument(instrument.location.source, instrument.location.line, instrument.id)
237233 val map: MutableMap <String , Any ?> = HashMap ()
238234 when (instrument) {
239235 is LiveBreakpoint -> map[" breakpoint" ] = ModelSerializer .INSTANCE .toJson(instrument)
@@ -273,7 +269,7 @@ object LiveInstrumentService {
273269 .collect(Collectors .toSet())
274270 instruments.addAll(
275271 applyingInstruments.values.stream()
276- .filter { it.instrument.location.source == source}
272+ .filter { it.instrument.location.source == source }
277273 .collect(Collectors .toSet()))
278274 return ArrayList (instruments)
279275 }
0 commit comments