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

Incremental build of builders fail #111

Closed
vukisoft opened this issue Mar 10, 2016 · 8 comments
Closed

Incremental build of builders fail #111

vukisoft opened this issue Mar 10, 2016 · 8 comments
Assignees
Labels

Comments

@vukisoft
Copy link

I realized that in some cases freebuilder fails to work unless I clean first.
In the following example, if I add the first only, it compiles (and works in IDE). However if I add the second too, all fails. It gets successful again if I do clean build (or clean in IDE - Eclipse).
This leads us to a kind of undeterministic behaviour, sometimes it works sometime it doesn't (until I clean).

public class Main {
  interface Foo<T> {
    T getBar();
  }

  @FreeBuilder
  interface GenericFoo<T> extends Foo<T> {
    class Builder<T> extends Main_GenericFoo_Builder<T> {}
  }

  @FreeBuilder
  interface StringFoo extends Foo<String> {
    class Builder extends Main_StringFoo_Builder {}
  }
}

We also found a situation where it does not work in IDE only, but otherwise builds properly, but I couldn't create an example class of that yet.

@alicederyn alicederyn added the bug label Mar 10, 2016
@alicederyn
Copy link
Collaborator

Okay, here are the errors I'm seeing when I do this in Eclipse 4.5.0:

  • Two "Source file already created" warnings, one on each @FreeBuilder annotation
  • An error on the Builder class in GenericFoo<T>, "Builder extends the wrong type (should be Main_GenericFoo_Builder)", which is generated by FreeBuilder and looks erroneous
  • A placeholder type is generated for Main_GenericFoo_Builder<T>
  • Multiple errors in Main_StringFoo_Builder caused by FreeBuilder generating invalid code that references undefined type T instead of String

When I clean and regenerate, I still see the errors in Main_StringFoo_Builder. If I explicitly override getBar in StringFoo, FreeBuilder stops outputting T in both cases, so that's a separate bug.

Does this match what you're seeing?

@vukisoft
Copy link
Author

For incremental build I see
Main.java:[23,27] cannot find symbol
symbol: class Main_StringFoo_Builder
location: interface foo.bar.Main.StringFoo
Main.java:[17,5] Builder extends the wrong type (should be Main_GenericFoo_Builder)

I don't see errors for clean build.
Also I don't see any of the warnings, but probably you're correct :)

So you will keep this and add separate bug, too?

@alicederyn
Copy link
Collaborator

Yes, though honestly this sounds like an eclipse bug, which is unlikely to have a workaround we can implement

@alicederyn
Copy link
Collaborator

Opened #112 for the other bug. Thanks!

@vukisoft
Copy link
Author

The error I quoted comes when building by maven! So it had nothing to do with Eclipse.
So:
mvn install with first inner class - ok
mvn install with both - fail
mvn clean install with both - ok

@alicederyn
Copy link
Collaborator

That's both really weird and really helpful. Thanks! I misunderstood your initial message.

@alicederyn alicederyn self-assigned this Mar 11, 2016
@j-baker
Copy link
Collaborator

j-baker commented Apr 3, 2016

Also been seeing this, in our case with:

package com.palantir.salt;

import com.palantir.salt.model.Version;
import java.time.Instant;
import org.inferred.freebuilder.FreeBuilder;

@FreeBuilder
public interface ValueAndMetadata<T> {
    T getValue();
    Version getVersion();
    Instant getTimestamp();

    class Builder<T> extends ValueAndMetadata_Builder<T> {}
}

Repro steps:

  1. Initial make (works fine)
  2. Make some changes in the same project, then click 'make' in IntelliJ - see error
  3. Click 'rebuild', and error disappears.

Generated code looks like

// Autogenerated code. Do not modify.
package com.palantir.salt;

import javax.annotation.Generated;

/**
 * Placeholder. Create {@code ValueAndMetadata<T>.Builder} and subclass this type.
 */
@Generated("org.inferred.freebuilder.processor.CodeGenerator")
abstract class ValueAndMetadata_Builder<T> {}

alicederyn added a commit that referenced this issue Apr 12, 2016
When an existing generated class is rebuilt without cleaning, javac will pick up the old .class file, and references to the generated type will not be ERRORs. This was triggering a bug in Analyser.IsSubclassOfGeneratedTypeVisitor when the generated type is generic.

This fixes issue #111.
@alicederyn
Copy link
Collaborator

This should be fixed in FreeBuilder 1.7.1. Sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants