Skip to content

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

@rgrunber

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions