Skip to content

does the cluster sort here actually reorder anything? its compare never says one cluster comes first, so the order looks random and which cluster gets split depends on that #14625

Open

Description

@DaanHoogland

does the cluster sort here actually reorder anything? its compare never says one cluster comes first, so the order looks random and which cluster gets split depends on that

Originally posted by @Damans227 in #14000 (comment)

    public static LinkedHashMap<Long, List<HostVO>> sortByClusterSize(final Map<Long, List<HostVO>> hostToClusterMap) {
        List<Long> keys = new ArrayList<Long>();
        keys.addAll(hostToClusterMap.keySet());
        Collections.sort(keys, new Comparator<Long>() {
            @Override
            public int compare(Long o1, Long o2) {
                List<HostVO> v1 = hostToClusterMap.get(o1);
                List<HostVO> v2 = hostToClusterMap.get(o2);
                if (v1 == null) {
                    return (v2 == null) ? 0 : 1;
                }

                if (v1.size() < v2.size()) {
                    return 1;
                } else {
                    return 0;
                }
            }
        });

        LinkedHashMap<Long, List<HostVO>> sortedMap = new LinkedHashMap<Long, List<HostVO>>();
        for (Long key : keys) {
            sortedMap.put(key, hostToClusterMap.get(key));
        }
        return sortedMap;
    }

Activity

  1. github-actions commented on Nov 9, 2026

    @github-actions

    Warning

    threat detection engine error
    The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

    What happened

    The threat detection engine failed to produce results.

    Review the workflow run logs for details.

    🎯 Triage report

    The comparator in sortByClusterSize returns 1 or 0 but never a negative value, so it does not define a valid ordering. Host-to-cluster entries are therefore not reliably sorted by cluster size, and which cluster is split depends on the input order. The issue was raised from review of PR #14000.

    📊 Assessment

    Dimension Value Reasoning
    Type type:bug Comparator contract violated; ordering is undefined
    Component n/a Affected code is not clearly tied to one component label
    Severity Severity:Minor Affects host ordering without a reported crash or data loss
    Labels type:bug, Severity:Minor
    Coding agent Suitable Small, self-contained fix: return a negative value when the first cluster is larger

    🔗 Similar issues

    💡 Notes and suggestions
    • The fix is likely a one-line comparator change; add a test that checks the order for clusters of different sizes.
    • A component label was not applied because the issue text does not name the affected area.

    Generated by Daily Issue Triage · copilot · haiku55 · ~4 AIC · ⊞ 3.8K · ◷

    Add this agentic workflow to your repo

    To install this agentic workflow, run

    gh aw add githubnext/agentics/workflows/daily-issue-triage.md@139fa09ef17cde4135e696ff8e7af09bc5ddfa6e
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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