Skip to content

Potential unhandled hash collisions #1

@Gattag

Description

@Gattag

It appears that you cache a data structure based on hashing but do not check for hash collisions, this looks like sneaky bug to me.

The following is in the SourceLocation companion:
introspekt-runtime/src/commonMain/kotlin/dev/karmakrafts/introspekt/util/SourceLocation.kt

        /**
         * Gets an existing [SourceLocation] from the cache or creates a new one if it doesn't exist.
         *
         * This method helps reduce memory usage by reusing instances with the same parameters.
         *
         * @param module The module name.
         * @param file The file name.
         * @param line The line number.
         * @param column The column number.
         * @return A [SourceLocation] instance with the specified parameters.
         */
        @IntrospektCompilerApi
        internal fun getOrCreate(module: String, file: String, line: Int, column: Int): SourceLocation {
            return cache.getOrPut(hash(module, file, line, column)) {
                SourceLocation( // @formatter:off
                    module = module,
                    file = file,
                    line = line,
                    column = column
                ) // @formatter:on
            }
        }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions