Skip to content

Autobuild triggers unnnecessary validation of all opened Java source files #1004

Closed

Description

@rgrunber

Steps to reproduce

  1. Import a simple Quarkus project (that has an application.properties and various different .java source files).
  2. Open a few Java source files
  3. Perform a "save" in any of the source files, even if no actual changes are made.

In the client/server logs you should notice :

logs
[Trace - 15:45:22] Sending notification 'textDocument/willSave'.
Params: {
    "textDocument": {
        "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/main/java/org/acme/config/GreetingResource.java"
    },
    "reason": 1
}


[Trace - 15:45:22] Sending request 'textDocument/willSaveWaitUntil - (76)'.
Params: {
    "textDocument": {
        "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/main/java/org/acme/config/GreetingResource.java"
    },
    "reason": 1
}

[Trace - 15:45:22] Received response 'textDocument/willSaveWaitUntil - (76)' in 17ms.
Result: []


[Trace - 15:45:22] Sending notification 'textDocument/didSave'.
Params: {
    "textDocument": {
        "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/main/java/org/acme/config/GreetingResource.java"
    },
    "text": "......."
}

[Trace - 15:45:22] Sending request 'workspace/executeCommand - (77)'.
Params: {
    "command": "microprofile/java/diagnostics",
    "arguments": [
        {
            "uris": [
                "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/test/java/org/acme/config/GreetingResourceIT.java",
                "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/test/java/org/acme/config/GreetingResourceTest.java",
                "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/main/java/org/acme/config/GreetingResource.java"
            ],
            "documentFormat": 2,
            "settings": {
                "patterns": []
            }
        }
    ]
}


[Trace - 15:45:22] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart",
    "diagnostics": []
}


[Trace - 15:45:22] Received notification 'textDocument/publishDiagnostics'.
Params: {
    "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/pom.xml",
    "diagnostics": []
}

[Trace - 15:45:22] Received request 'workspace/executeClientCommand - (35)'.
Params: {
    "command": "microprofile/propertiesChanged",
    "arguments": [
        {
            "type": [
                1
            ],
            "projectURIs": [
                "/home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart"
            ]
        }
    ]
}

[Trace - 15:45:22] Received response 'workspace/executeCommand - (77)' in 92ms.
Result: [
    {
        "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/test/java/org/acme/config/GreetingResourceIT.java",
        "diagnostics": []
    },
    {
        "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/test/java/org/acme/config/GreetingResourceTest.java",
        "diagnostics": []
    },
    {
        "uri": "file:///home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart/src/main/java/org/acme/config/GreetingResource.java",
        "diagnostics": []
    }
]

So a save in a single Java source file triggers validation in all other files, even though they all remain unchanged.

Explanation

The reason this happens is because the moment a file is saved, the JDT auto-builder runs and delegates to M2E's builder. M2E runs maven-resources-plugin to copy src/main/resources/ into target/classes/ (as per the Quarkus project pom file) . It seems that plugin is clever enough to distinguish between modification (file content changes) & changes (file metadata changes) but the Eclipse platform makes no distinction. It considers the file has changed if the timestamp for it is different, which it is. It broadcasts a resource change event for the application.properties and ultimately this results in microprofile/propertiesChanged notification being sent back to the MicroProfile LS, which then triggers validation on all files.

This is probably a pure vscode-microprofile issue, but figured I'd report here for a bit more visibility. Also, as a small note, validation on all opened files will still get triggered purely from saving a source file. However, the issues is that validation is being triggered more than it should be.

Solution(s)

Disabling the autobuilder (java.autobuild.enabled to false) is a possible workaround. The issue can't happen if a build doesn't occur on save. Not very ideal though.

The better solution is to store a checksum of the file in order to only call microprofile/propertiesChanged if the properties file has actually changed.

Activity

  1. changed the title [-]Autobuild triggers unnnecessary validationof all opened Java source files[/-] [+]Autobuild triggers unnnecessary validation of all opened Java source files[/+] on Apr 16, 2025
  2. angelozerr commented on Apr 16, 2025

    @angelozerr
    Contributor

    I need to check that, but in IJ Quarkus we have not this problem.

    The problem is as you said. Is MP JDT send microprofile/propertiesChanged.

    So the fix must be done in MP JDT side to avoid sending a microprofile/propertiesChanged and not in MP LS side.

    I have not tested but perhaps the fix is to send a microprofile/propertiesChanged by using a resource listener by tracking the application.properties from src and not from target.

  3. angelozerr commented on Apr 16, 2025

    @angelozerr
    Contributor

    And I need to investigate again but I wonder if we need this microprofile/propertiesChanged?

    Perhaps a fix is to remove this microprofile/propertiesChanged and trigger java validation on didSave of the application.properties on the MP LS side.

  4. angelozerr commented on May 14, 2025

    @angelozerr
    Contributor

    @rgrunber

    [Trace - 15:45:22] Received request 'workspace/executeClientCommand - (35)'.
    Params: {
        "command": "microprofile/propertiesChanged",
        "arguments": [
            {
                "type": [
                    1
                ],
                "projectURIs": [
                    "/home/rgrunber/sample-projects/quarkus-quickstarts/config-quickstart"
                ]
            }
        ]
    }
    

    means that a Java file has been saved (type is equals to 1)

    The problem that I have seen is that when you save a Java file, it validate twice all Java files. Here a trace with 3 opened Java files and a save has been done:

    [Trace - 9:33:16 PM] Sending notification 'textDocument/didSave'.
    Params: {
        "textDocument": {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java"
        }
    }
    
    
    [Trace - 9:33:16 PM] Received request 'microprofile/java/diagnostics - (56)'.
    Params: {
        "uris": [
            "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java",
            "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/DemoRestApplication.java",
            "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/resilient/ResilienceController.java"
        ],
        "documentFormat": 2,
        "settings": {
            "patterns": []
        }
    }
    
    
    [Trace - 9:33:16 PM] Sending notification 'microprofile/propertiesChanged'.
    Params: {
        "type": [
            1
        ],
        "projectURIs": [
            "C:\\Users\\azerr\\Downloads\\demo\\demo"
        ]
    }
    
    
    [Trace - 9:33:16 PM] Sending response 'microprofile/java/diagnostics - (56)'. Processing request took 121ms
    Result: [
        {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java",
            "diagnostics": []
        },
        {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/DemoRestApplication.java",
            "diagnostics": []
        },
        {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/resilient/ResilienceController.java",
            "diagnostics": []
        }
    ]
    
    
    [Trace - 9:33:16 PM] Received notification 'textDocument/publishDiagnostics'.
    Params: {
        "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java",
        "diagnostics": []
    }
    
    
    [Trace - 9:33:16 PM] Received notification 'textDocument/publishDiagnostics'.
    Params: {
        "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/DemoRestApplication.java",
        "diagnostics": []
    }
    
    
    [Trace - 9:33:16 PM] Received notification 'textDocument/publishDiagnostics'.
    Params: {
        "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/resilient/ResilienceController.java",
        "diagnostics": []
    }
    
    
    [Trace - 9:33:16 PM] Sending notification 'microprofile/propertiesChanged'.
    Params: {
        "type": [
            3
        ],
        "projectURIs": [
            "C:\\Users\\azerr\\Downloads\\demo\\demo"
        ]
    }
    
    
    [Trace - 9:33:16 PM] Received request 'microprofile/java/diagnostics - (57)'.
    Params: {
        "uris": [
            "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java",
            "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/DemoRestApplication.java",
            "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/resilient/ResilienceController.java"
        ],
        "documentFormat": 2,
        "settings": {
            "patterns": []
        }
    }
    
    
    [Trace - 9:33:16 PM] Sending response 'microprofile/java/diagnostics - (57)'. Processing request took 16ms
    Result: [
        {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java",
            "diagnostics": []
        },
        {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/DemoRestApplication.java",
            "diagnostics": []
        },
        {
            "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/resilient/ResilienceController.java",
            "diagnostics": []
        }
    ]
    
    
    [Trace - 9:33:16 PM] Received notification 'textDocument/publishDiagnostics'.
    Params: {
        "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/HelloController.java",
        "diagnostics": []
    }
    
    
    [Trace - 9:33:16 PM] Received notification 'textDocument/publishDiagnostics'.
    Params: {
        "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/DemoRestApplication.java",
        "diagnostics": []
    }
    
    
    [Trace - 9:33:16 PM] Received notification 'textDocument/publishDiagnostics'.
    Params: {
        "uri": "file:///c%3A/Users/azerr/Downloads/demo/demo/src/main/java/com/example/demo/resilient/ResilienceController.java",
        "diagnostics": []
    }
    
    

    As you can see all opened Java files are validated twice:

    • the first comes from the Java which have changed
    [Trace - 9:33:16 PM] Sending notification 'microprofile/propertiesChanged'.
    Params: {
        "type": [
            1
        ],
        "projectURIs": [
            "C:\\Users\\azerr\\Downloads\\demo\\demo"
        ]
    }
    
    
    • the second is the problem that you have explained (type=3 means properties file changed)
    [Trace - 9:33:16 PM] Sending notification 'microprofile/propertiesChanged'.
    Params: {
        "type": [
            3
        ],
        "projectURIs": [
            "C:\\Users\\azerr\\Downloads\\demo\\demo"
        ]
    }
    

    I don't remember why a Java save, retrigger validation for all opened Java files (let me investigate that), but the type=3 must never sent to avoid twice validation.

  5. angelozerr commented on May 14, 2025

    @angelozerr
    Contributor
  6. rgrunber commented on May 14, 2025

    @rgrunber
    MemberAuthor

    I thought because content in one Java source file could affect content in the others (eg. using API from one file that is used in the other). Same goes for properties file changing. If a properties key/value is removed in a config file, then maybe certain config property annotations from an opened file need a warning about missing value.

    I'm sure there's a good reason why we validate. But if we can avoid it for better performance, it may be worth it. Also, sometimes "diagnostics": [] just means that something has requested the diagnostics be cleared.

  7. moved this to Todo in Java Toolingon Jul 7, 2025
  8. moved this from Todo to Pending review in Java Toolingon Jul 28, 2025
  9. moved this from Pending review to In Progress in Java Toolingon Jul 28, 2025
  10. datho7561 commented on Apr 22, 2026

    @datho7561
    Contributor

    @angelozerr This is fixed by #546, right?

  11. angelozerr commented on Apr 22, 2026

    @angelozerr
    Contributor

    Yes it should.

  12. datho7561 commented on Apr 22, 2026

    @datho7561
    Contributor
  13. moved this from In Progress to Done in Java Toolingon Apr 22, 2026
  14. modified the milestone: 1.22.1 on Apr 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions