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

Inconstancy of builder API #66

Closed
ncoquelet opened this issue Nov 16, 2017 · 6 comments
Closed

Inconstancy of builder API #66

ncoquelet opened this issue Nov 16, 2017 · 6 comments

Comments

@ncoquelet
Copy link

If I create an analyzer instance with builder like this, this works as except :
UserAgentAnalyzer analyzer = UserAgentAnalyzer.newBuilder().withField("DeviceClass").withoutCache().build();

But if I move the withoutCache() call at the beginning, the API contract isn't the same and a nocache instance is return.
UserAgentAnalyzer analyzer = UserAgentAnalyzer.newBuilder().withoutCache().withField("DeviceClass").build();

This break my eclipse compilation.

@nielsbasjes
Copy link
Owner

I did some quick tests by manually inspecting these two instances and I have not been able to find any difference between them.

UserAgentAnalyzer analyzer1 = UserAgentAnalyzer.newBuilder().withField("DeviceClass").withoutCache().build();
UserAgentAnalyzer analyzer2 = UserAgentAnalyzer.newBuilder().withoutCache().withField("DeviceClass").build();

What version are you using?

@ncoquelet
Copy link
Author

Hi,
I'm using the version 3.1
The stranger thing is when I compile my code with the jdk in maven, I don't get an error.
But in Eclipse, if I place withField() after withoutCache(), it return an UserAgentAnalyzerDirectBuilder instead of UserAgentAnalyzerBuilder, so the build() return an UserAgentAnalyzerDirect instance.

@nielsbasjes
Copy link
Owner

That is very strange.
All methods in the Builder return a value of the type specified in the generic, which the class from which you called the static method newBuilder.
So this effect you describe should not occur.
I'm using IntelliJ IDEA and there I do not have any problems like this.

At this point I'm guessing you found a bug in Eclipse caused by this type of use of generics.

Can you please try this with a different IDE? Perhaps Netbeans or IntelliJ?

@nielsbasjes
Copy link
Owner

nielsbasjes commented Nov 19, 2017

I installed Eclipse on my machine to see what actually happens. As far as I can see this is a bug in Eclipse.

@nielsbasjes
Copy link
Owner

I have filed a bug report with the Eclipse project.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=527475

@nielsbasjes
Copy link
Owner

Thank you for reporting this.

I checked this code against the Java 1.8 compiler, IntelliJ (latest), NetBeans 8.1 and the latest Eclipse.

Only Eclipse shows this problem.
So I filed a bug report with the Eclipse project and I documented this problem in the README.md of this project.

The workaround: Use a different IDE until Eclipse fixes this.

I'm closing this report because there is no problem with this project.

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

No branches or pull requests

2 participants