Skip to content

Commit

Permalink
Fixed: ConcurrentModificationException in UnignoreFileGroupAction#Get…
Browse files Browse the repository at this point in the history
…Children #860
  • Loading branch information
hsz committed Oct 6, 2023
1 parent cb79a19 commit bb98caa
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fixed `com.intellij.openapi.util.TraceableDisposable$DisposalException: Double release of editor`
- Improve module root detection in Rider
- Fixed issue when starring the template, marks both `gitignore` and `toptal` entries [\#844](https://github.com/hsz/idea-gitignore/issues/844)
- Fixed ConcurrentModificationException in UnignoreFileGroupAction#GetChildren [\#860](https://github.com/hsz/idea-gitignore/issues/860)

## [4.5.1] - 2023-06-22
- Fixed `Slow operations are prohibited on EDT` [\#831](https://github.com/hsz/idea-gitignore/issues/831)
Expand Down
17 changes: 10 additions & 7 deletions src/main/kotlin/mobi/hsz/idea/gitignore/IgnoreManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ class IgnoreManager(private val project: Project) : DumbAware, Disposable {

private val commonRunnableListeners = CommonRunnableListeners(debouncedStatusesChanged)
private var messageBus = project.messageBus.connect(this)
private val cachedIgnoreFilesIndex =
CachedConcurrentMap.create<IgnoreFileType, List<IgnoreEntryOccurrence>> { key -> IgnoreFilesIndex.getEntries(project, key) }
private val cachedIgnoreFilesIndex = CachedConcurrentMap.create<IgnoreFileType, List<IgnoreEntryOccurrence>> {
IgnoreFilesIndex.getEntries(project, it)
}

private val expiringStatusCache = ExpiringMap<VirtualFile, Boolean>(Time.SECOND)

Expand Down Expand Up @@ -98,11 +99,13 @@ class IgnoreManager(private val project: Project) : DumbAware, Disposable {
}

private fun handleEvent(event: VFileEvent) {
val fileType = event.file?.fileType
if (fileType is IgnoreFileType) {
cachedIgnoreFilesIndex.remove(fileType)
expiringStatusCache.clear()
debouncedStatusesChanged.run()
ApplicationManager.getApplication().runReadAction {
val fileType = event.file?.fileType
if (fileType is IgnoreFileType) {
cachedIgnoreFilesIndex.remove(fileType)
expiringStatusCache.clear()
debouncedStatusesChanged.run()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.util.text.StringUtil
import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.containers.ContainerUtil
import com.intellij.util.containers.addIfNotNull
import mobi.hsz.idea.gitignore.IgnoreBundle
import mobi.hsz.idea.gitignore.file.type.IgnoreFileType
Expand All @@ -27,7 +28,7 @@ open class IgnoreFileGroupAction(
) : ActionGroup() {

/** List of suitable Gitignore [VirtualFile]s that can be presented in an IgnoreFile action. */
private val files = mutableMapOf<IgnoreFileType, List<VirtualFile>>()
private val files = ContainerUtil.createConcurrentWeakMap<String, List<VirtualFile>>()

@PropertyKey(resourceBundle = IgnoreBundle.BUNDLE_NAME)
private val presentationTextSingleKey: String
Expand Down Expand Up @@ -65,7 +66,7 @@ open class IgnoreFileGroupAction(
// skip already bundled languages for ignore action
.filterNot { this !is UnignoreFileGroupAction && (it is GitLanguage || it is MercurialLanguage) }
.map { it.fileType }
.forEach { files[it] = getSuitableIgnoreFiles(project, it, file).reversed() }
.forEach { files[it.languageName] = getSuitableIgnoreFiles(project, it, file).reversed() }
} catch (e: ExternalFileException) {
presentation.isVisible = false
}
Expand Down Expand Up @@ -100,7 +101,7 @@ open class IgnoreFileGroupAction(
}

templatePresentation.apply {
icon = key.icon
icon = IgnoreBundle.LANGUAGES[key]?.icon
text = name
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentMap
*/
class CachedConcurrentMap<K, V> private constructor(private val fetcher: DataFetcher<K, V>) {

private val map: ConcurrentMap<K, V> = ContainerUtil.createConcurrentWeakMap()
private val map: ConcurrentMap<K & Any, V & Any> = ContainerUtil.createConcurrentWeakMap()

companion object {
fun <K, V> create(fetcher: DataFetcher<K, V>) = CachedConcurrentMap(fetcher)
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
file="colorSchemes/IgnoreDarcula.xml"
scheme="Darcula"/>

<applicationService
serviceImplementation="mobi.hsz.idea.gitignore.settings.IgnoreSettings"/>
<applicationService
serviceImplementation="mobi.hsz.idea.gitignore.settings.IgnoreSettings"/>

<colorSettingsPage
implementation="mobi.hsz.idea.gitignore.highlighter.IgnoreColorSettingsPage"/>
Expand Down

0 comments on commit bb98caa

Please sign in to comment.