Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotation processors are not reinvoked if member element order changes #2

Open
Sipkab opened this issue Dec 31, 2019 · 0 comments
Open
Labels
bug Something isn't working

Comments

@Sipkab
Copy link
Member

Sipkab commented Dec 31, 2019

If an annotation processor queries the Element.getEnclosedElements() and generates results that implicitly depends on the order of the elements, then the processor will not be reinvoked when the enclosed element order is changed. As an example:

public class Subject {
    public int a;
    public int b;
}

The processor may generate a resource with the following contents

a[...]
b[...]

If the developer decides to only change up the order of the elements as:

public class Subject {
    public int b;
    public int a;
}

Then the processor would generate:

b[...]
a[...]

However, the processor is not reinvoked by the incremental compiler task.

This is a bug.

Workaround

Perform a clean build or the processor shouldn't depend on the element order. Alphabetic sorting may be a good solution.

Solution

Track the behaviour of the processors and the expected indexes for the associated elements. If the indexes change, reinvoke the processors.

We might consider adding a flag to the processor configuration to signal that a given processor actually depends on the element order. As most processors probably don't, tracking them could introduce some overhead.

Another note that is that we might get away by only tracking the relative order between elements that were reported as input dependencies to a given resource generation. This should be much easier to implement and more straight forward from a Processor perspective.

@Sipkab Sipkab added the bug Something isn't working label Dec 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

No branches or pull requests

1 participant