From cf4727f38455fa888bc1b2d7723021c3418e1afe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Tue, 30 Jan 2024 09:04:24 +0100 Subject: [PATCH] Sort filename (if given) by name for consistent output Currently the generation of lamdas can change depending on when the source file is processed. This sorts the array of files (if given) to always have a predictable order independent of order given on the commandline / arguments. Relates to https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1921 --- .../org/eclipse/jdt/internal/compiler/batch/Main.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java index a43ae4c47a9..0c0fc64457a 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/batch/Main.java @@ -72,6 +72,7 @@ import java.util.Set; import java.util.StringTokenizer; import java.util.function.Function; +import java.util.stream.IntStream; import org.eclipse.jdt.core.compiler.CategorizedProblem; import org.eclipse.jdt.core.compiler.CharOperation; @@ -3362,9 +3363,13 @@ public CompilationUnit[] getCompilationUnits() { String defaultEncoding = this.options.get(CompilerOptions.OPTION_Encoding); if (Util.EMPTY_STRING.equals(defaultEncoding)) defaultEncoding = null; - + // sort index by file names so we have a consistent order of compiling / handling them + // this is important as the order can influence the way for example lamda numbers are generated + int[] orderedIndex = IntStream.range(0, fileCount).boxed().sorted((i1, i2) -> { + return this.filenames[i1].compareTo(this.filenames[i2]); + }).mapToInt(i -> i).toArray(); for (int round = 0; round < 2; round++) { - for (int i = 0; i < fileCount; i++) { + for (int i : orderedIndex) { char[] charName = this.filenames[i].toCharArray(); boolean isModuleInfo = CharOperation.endsWith(charName, TypeConstants.MODULE_INFO_FILE_NAME); if (isModuleInfo == (round==0)) { // 1st round: modules, 2nd round others (to ensure populating pathToModCU well in time)