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
Bug: unable to create instance of IteratorTester
#5254
Comments
Not at my computer, but will Java let you import it as IteratorTester.KnownOrder? |
Aha, yes I can import But this only works if I use it inline like so: new IteratorTester<String>(
3, IteratorFeature.UNMODIFIABLE, Arrays.asList("a", "b", "c"), IteratorTester.KnownOrder.KNOWN_ORDER) {
@Override
protected Iterator<String> newTargetIterator() {
return iterable.iterator();
}
}; If I try the following, it fails to compile: import com.google.common.collect.testing.IteratorTester.KnownOrder;
...
new IteratorTester<String>(
3, IteratorFeature.UNMODIFIABLE, Arrays.asList("a", "b", "c"), KnownOrder.KNOWN_ORDER) {
@Override
protected Iterator<String> newTargetIterator() {
return iterable.iterator();
}
}; Specifically it fails with the following message:
The second option - using it in an |
Ah sorry, actually IntelliJ suggests that I This seems to suggest more that it's an IntelliJ bug... Thoughts? |
Regardless, I think that |
Yeah, this is all unfortunate. I'd be happy to look at a PR for Javadoc. Ideally we'll someday fix the API, but we'd have to think about how to do that without too much additional disruption and confusion. |
Okay! I'm more than happy to provide a PR, but I don't yet know when I'll have the time to do it. I'll keep you posted. |
I made a mistake and accidentally included an example that does not compile. Specifically, importing `KnownOrder` as-is does not compile; instead one needs to import `IteratorTester.KnownOrder`. See google#5254 for more information. I also changed the example to use `Collections#unmodifiableList` rather than `ArrayList` because `ArrayList#iterator` does not satisfy all the requirements of `IteratorFeature#MODIFIABLE`.
I made a mistake and accidentally included an example that does not compile. Specifically, importing `KnownOrder` as-is does not compile; instead one needs to import `IteratorTester.KnownOrder`. See #5254 for more information. I also changed the example to use `Collections#unmodifiableList` rather than `ArrayList` because `ArrayList#iterator` does not satisfy all the requirements of `IteratorFeature#MODIFIABLE`. Fixes #5276 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=336911192
I made a mistake and accidentally included an example that does not compile. Specifically, importing `KnownOrder` as-is does not compile; instead one needs to import `IteratorTester.KnownOrder`. See #5254 for more information. I also changed the example to use `Collections#unmodifiableList` rather than `ArrayList` because `ArrayList#iterator` does not satisfy all the requirements of `IteratorFeature#MODIFIABLE`. Fixes #5276 RELNOTES=n/a ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=336911192
Bug description
When I attempt to create an instance of
com.google.common.collect.testing.IteratorTester
fromguava-testlib
version 29-jre, I end up with the following compilation error message:My workaround is to copy
IteratorTester
,AbstractIteratorTester
andHelpers
into my project.How to reproduce
git clone https://github.com/jbduncan/iteratortester-compilation-bug.git
./gradlew build
Possible fixes
AbstractIteratorTester
public and its constructor non-public, documenting that it's not intended to be extendedKnownOrder
into a separate file (breaking change)IteratorTester
non-public, at the risk of making guava-testlib users except Guava itself not being able to use it anymore (breaking change)The text was updated successfully, but these errors were encountered: