Vineflower / vineflower

Modern Java decompiler aiming to be as accurate as possible, with an emphasis on output quality. Fork of the Fernflower decompiler.
https://vineflower.org/
Apache License 2.0
1.13k stars 83 forks source link

Blank lines with spaces in the decompiled source #359

Closed Machine-Maker closed 2 months ago

Machine-Maker commented 2 months ago

Vineflower version

1.11.0-20240406.040032-5

Describe the bug

Some files seem to have spaces on blank lines.

Additional information

There are tons of examples, you can just do a fresh decompile of Minecraft and to a regex search for lines that only contain spaces. This is an example from net.minecraft.data.recipes.RecipeProvider.

private static final Map<BlockFamily.Variant, BiFunction<ItemLike, ItemLike, RecipeBuilder>> SHAPE_BUILDERS = ImmutableMap.<BlockFamily.Variant, BiFunction<ItemLike, ItemLike, RecipeBuilder>>builder(
            // spaces until here on L50
        )
        .put(BlockFamily.Variant.BUTTON, (output, input) -> {
            return buttonBuilder(output, Ingredient.of(input));
        })
jaskarth commented 2 months ago

Fixed by #362, thank you for the report!

Machine-Maker commented 2 months ago

I guess it technically fixed the one I listed in the issue, but there are still tons of other cases of extra spaces on blank lines. I'll open a new report with as many cases as I can find that seem different.

jaskarth commented 2 months ago

I think it'll be okay to re-use this one. I'll reopen it, feel free to add the new cases here.

Machine-Maker commented 2 months ago

Well actually, intellij has this handy export findings to txt file. So here is all of the offenders in the mc source. I searched for ^\s\s\s\s*$.

jpenilla commented 2 months ago

This test case reproduces the issue:

   static {
      takeLambda00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000(// 13
         () -> {
            for (int i = 0; i < 10; i++) {// 14
               System.out.println(i);// 15
            }

            if (new Random().nextBoolean()) {// 17
               System.out.println(true);// 18
            }
         }// 20
      );
   }// 21

  static void takeLambda00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000(Runnable r) {
  }

The issue is basically that the lambda argument's indent is being appended to blank lines in the lambda. Also worth noting the issue goes away when the method name is changed to be reasonable and the formatter no longer needs to add indent.