class UpgradeService {

    @PostConstruct
    void sortAndCheckTasks() { // NOSONAR called by @PostConstruct annotation
        Collections.sort(tasks);

        Map<String, List<Integer>> groupTasks = new HashMap<>();
        List<UpgradeTaskId> conflictTasks = new ArrayList<>();
        tasks.stream().map(UpgradeTask::getId).forEach(id -> {
            // add the version entry if needed
            if (!groupTasks.containsKey(id.getVersion())) {
                groupTasks.put(id.getVersion(), new ArrayList<>());
            }
            // check if there's already a task for this order
            final List<Integer> orders = groupTasks.get(id.getVersion());
            if (orders.contains(id.getOrder())) {
                conflictTasks.add(id);
            } else {
                orders.add(id.getOrder());
            }
        });

        if (!conflictTasks.isEmpty()) {
            throw new IllegalArgumentException("The are " + conflictTasks.size()
                    + " conflicted upgrade tasks (task with the same order for one version) : " + conflictTasks);
        }
    }

}