Commit Graph
2085 Commits
Author SHA1 Message Date
Guice TeamandGuice Team 6412858fca Internal change.
PiperOrigin-RevId: 538300298
2023-06-06 15:00:05 -07:00
Sam BerlinandGuice Team c58bc33b90 A bunch of environment changes.
* Bump minimum JRE to 11 (from 8).
* Change testing matrix from {8,11,15,17} to {11,17,21-ea}. (Except the bazel build has trouble parsing "21-ea" as a java version, so s/21-ea/20 for bazel.)
* Also test on macos (but only with jdk17). (Attempted to test on windows too, but there's issues right now.)
* Cleanup the POMs a little bit (remove unused mailing list reference, fix CI link)
* Bump bazel version to 6.2.0, otherwise the tests fail b/c they try to set a security manager (see https://github.com/bazelbuild/bazel/issues/14502, which was fixed in https://github.com/bazelbuild/bazel/commit/7556e1107b666d10b660470a571631463c7eb4ec, which was cherrypicked into the 6.2.0 release). This also required suppressing the "BanJNDI" errorprone check in the JNDI extension, which was also added to 6.2.0. (A future change should probably just remove the JNDI extension altogether.)

PiperOrigin-RevId: 532849632
2023-05-17 11:22:54 -07:00
Sam BerlinandGuice Team ed5f5aec71 Bump last stable release to 7.0.0, update README to point to 6.0.0 & 7.0.0 as the last releases, update the 6.0.0 & 7.0.0 release pages.
PiperOrigin-RevId: 531554646
2023-05-12 11:10:25 -07:00
Hannes WellmannandGuice Team f4a66b797e Make error_prone_annotations dependency optional
Annotations with retention policy are ignored if they cannot be loaded at runtime (at least according to [Stack-Overvflow](https://stackoverflow.com/questions/3567413/why-doesnt-a-missing-annotation-cause-a-classnotfoundexception-at-runtime)). Make the dependency optional to not enforce the presence of error_prone_annotations in a java runtime even if those annotations are not used at all.

This is especially useful for OSGi-runtimes where you cannot exclude error_prone_annotations because the corresponding package is specified as mandatory requirement in the MANIFEST.MF. Marking the Maven dependency as optional will also result in the error-prone package requirement being marked as optional.

At the moment error_prone_annotations does not come with a OSGi compliant Manifest, which makes it harder to include it in OSGi applications like Eclipse.
I already created a PR at error-prone to include the required OSGi headers (see https://github.com/google/error-prone/pull/3903), but not requiring the annotations at all would make it even simpler to use guice within OSGi.

Alternatively the dependency could be marked as optional in the OSGi metadata.

Fixes #1739

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/guice/pull/1739 from HannesWell:optionalErrorproneAnnotations 86f9de0e50
PiperOrigin-RevId: 531531783
2023-05-12 09:48:36 -07:00
Sam BerlinandGuice Team 654032a954 Internal change.
PiperOrigin-RevId: 531069248
2023-05-10 19:42:14 -07:00
Sam BerlinandGuice Team bee813b7cc Improve MissingImplementationError to lazily calculate suggestions and standardize its output.
The error will now generate suggestions only when the message is used (as opposed to on instantiation). This should significantly improve the performance of any code that happens to call `injector.get{Instance,Provider,Binding}` and catches/ignores a `ProvisionException` (with the intention of falling back to code that deals with the type not being bound). While this isn't a great pattern for code to use, and there are far better ways of doing it... there's enough code that does this that it's worthwhile improving.

This pattern in particular was very problematic with the introduction of the jakarta.inject.Provider variants for Multibinders/MapBinders & OptionalBinders, because we have *lots* of those. By adding N more bindings to each multi/map/optionalbinder, we added a very large number of bindings to the overall total, which resulted in code using this pattern getting much slower.

This code also fixes suggestions to skip "UntargettedBindings", which are bindings like `bind(SomeInterface.class)` and aren't a valid suggestion (because they're missing a .to(..)). By standardizing, this otherwise broke a test in BinderTest that was asserting we failed those with proper error messages (showing their source). We would have otherwise started showing their source twice, once in a "Did you mean?" section and again in the normal "bound here" section. But really we shouldn't show these in "Did you mean?" at all, because it's just a repetition (or incorrect suggestion) of the wrong binding.

PiperOrigin-RevId: 531062151
2023-05-10 18:47:53 -07:00
Sam BerlinandGuice Team 2d64067e99 Use linked bindings for MapBinder/Multibinder/OptionalBinder aliases, instead of linking to the same internal factory implementation. (Reusing the internal factory results in some quirks that we want to avoid.)
PiperOrigin-RevId: 530977598
2023-05-10 12:34:58 -07:00
Sam BerlinandGuice Team be0141cc0d Internal change
PiperOrigin-RevId: 530658894
2023-05-09 11:03:32 -07:00
Sam BerlinandGuice Team 40a5bcfab5 Avoid re-initializing factories that are already initialized. This is necessary because we share the internal factory implementation, which leads to initialize(..) being called multiple times. There are other consequences/quirks of this, but re-initialization is the worst of it.
PiperOrigin-RevId: 530339379
2023-05-08 10:23:36 -07:00
Sam BerlinandGuice Team 9ac476784e Change the way we reference what 6.0 supports in the README, so it doesn't get transformed into jakarta.
Also note that 5.1 only supports javax.

PiperOrigin-RevId: 529858655
2023-05-05 18:02:04 -07:00
Sam BerlinandGuice Team 24324ca6c6 Prepare for the Guice 6.0 & 7.0 releases. This change does the following:
* Bumps the snapshot version to 7.0.1-SNAPSHOT
* Adds Guice 6 & Guice 7 release pages, with explanations of the jakarta transition & how Guice 6.0 & 7.0 should be used. They also include changelogs since 5.1.0.
* Updates the top-level README to reference the 6.0 & 7.0 releases, as well as including "installation instructions" (which fixes #1698).
* Updates the wiki to make sure it's meaningful for both javax & jakarta references, pointing to the correct ones where appropriate.

PiperOrigin-RevId: 529770936
2023-05-05 11:33:15 -07:00
Sam BerlinandGuice Team 49b1a33c59 Remove redundant references to javax.{inject,persistence,servlet} and replace the rest with their jakarta variants.
This required upgrading some test dependencies, because the tests need some impls of the APIs which only exist in newer releases.

This also removes the struts2 extension from the maven & bazel build (although it keeps the now-unused source), because struts2 has no release that supports jakarta. For users that want to continue using the struts2 extension, please continue to use the Guice 6.0 release (instead of the 7.0+ line, which will only support the jakarta dependencies).

Fixes #1383.

(I'll cut the 6.0 candidates/releases from before this commit, and if we need to make further 6.0 changes, I'll manually merge those into the 6.0 branch.)

PiperOrigin-RevId: 529504991
2023-05-04 13:50:43 -07:00
Sam BerlinandGuice Team 5a58425454 Rework sun.misc.Unsafe usages so that we directly refer to sun.misc.Unsafe, and call getObject on it natively instead of through reflection. (Take 2, after exempting its usages internally.)
Calling getObject through reflection breaks Azul JVMs, because the staticFieldBase is a funny "not object", but when passed through reflection it tries to become an Object and fails.

Retrieval of the unsafe is based on how other google open source projects do it, see for example AbstractFuture, UnsignedBytes, and protobufs.

Fixes #1719, and properly fixes #1672.

(Note that this change also bumps the Github Action's bazel version from 4.2.2 to 6.1.2, because somewhere along the way from 4.2.2->6.1.2, Bazel fixed the --javacopts="--release 8" option to also allow sun.misc.Unsafe.)

PiperOrigin-RevId: 529486761
2023-05-04 12:46:50 -07:00
Sam BerlinandGuice Team e7513e64a4 Breaks some conformance around sun.misc.Unsafe usage.
PiperOrigin-RevId: 529476888
2023-05-04 12:06:56 -07:00
Sam BerlinandGuice Team bb931fe974 Expose _something_ from private modules used in tests where the test is validating that the parent can't re-bind something from the private module. If nothing is exposed, the child/private injector can otherwise be immediately GC'd (which then allows the parent to have the binding). (Note that there are other ways the child/private module could be captured: such as a Provider or its Injector being captured into a longer-lived Thread... but this is the simplest way to do it). This is happening with some regularity on the Github Actions tests, making the tests a bit flaky.
PiperOrigin-RevId: 529467328
2023-05-04 11:33:20 -07:00
Sam BerlinandGuice Team 95a2fbbbf4 Rework sun.misc.Unsafe usages so that we directly refer to sun.misc.Unsafe, and call getObject on it natively instead of through reflection.
Calling getObject through reflection breaks Azul JVMs, because the staticFieldBase is a funny "not object", but when passed through reflection it tries to become an Object and fails.

Retrieval of the unsafe is based on how other google open source projects do it, see for example [AbstractFuture](https://github.com/google/guava/blob/d4bd0c5ffa913104283e61aeb2c41bac641af042/guava/src/com/google/common/util/concurrent/AbstractFuture.java#L1340-L1365), [UnsignedBytes](https://github.com/google/guava/blob/6405852bbf453b14d097b8ec3bcae494334b357d/guava/src/com/google/common/primitives/UnsignedBytes.java#L341-L366), and [protobufs](https://github.com/protocolbuffers/protobuf/blob/520c601c99012101c816b6ccc89e8d6fc28fdbb8/java/core/src/main/java/com/google/protobuf/UnsafeUtil.java#L289-L315).

Fixes #1719, and properly fixes #1672.

(Note that this change also bumps the Github Action's bazel version from 4.2.2 to 6.1.2, because somewhere along the way from 4.2.2->6.1.2, Bazel fixed the `--javacopts="--release 8"` option to also allow `sun.misc.Unsafe`.)

PiperOrigin-RevId: 529465570
2023-05-04 11:27:53 -07:00
Sam BerlinandGuice Team 3bb74d7e3b Improve the error message if an EntityManager is provisioned before a unit if work is started, to help users transition to the new default that requires an explicit work open (or the legacy option set).
PiperOrigin-RevId: 529465168
2023-05-04 11:26:21 -07:00
Sam BerlinandGuice Team bb54925a2c Some prefactorings that will make it easier to add transformations that strip javax and only use the jakarta variants.
* BoundFieldModule: just say "Provider" and "Qualifier" instead of FQN of each.
* MapBinderTest/MultibinderTest/SpiUtils/ProvidersTest/googlecode.guice.BUILD: reorder some things so it's easier to strip the javax variants
* OptionalBinderTest: introduce a helper that the tests delegate to, so the strip directives can be consolidated
* ContinuingRequestIntegrationTest/ServletTest: Don't pass null for the response in tests that made that fail, pass mocks instead. Earlier HttpServlet impls allowed null, later HttpServlet impls don't allow null.
* ElementsTest: rename javax-referencing to "spec" so it makes sense when its transformed.
* InjectorSpiTest: Run the formatter, since the next CL would have changed this.
* BoundFieldModuleTest: Reference javax explicitly in some places, explicitly don't reference it in others.
* OSGiContainerTest: Add a TODO about the test's uselessness
* pom.xml: Enable maven test failures to include stack traces, so we have some idea WTF went wrong when things go wrong.

PiperOrigin-RevId: 529463507
2023-05-04 11:20:49 -07:00
Sam BerlinandGuice Team 75df9fc285 Fix a few more places where we should check jakarta variants: DaggerMethodScanner scopes and BytecodeGenTest.
PiperOrigin-RevId: 528900279
2023-05-02 15:11:08 -07:00
Riley ParkandGuice Team 4cea39777a Bind the Provider from Jakarta when creating bindings with a Multibinder, MapBinder & OptionalBinder.
(This is a slightly modified version of @kashike's original PR @ #1715, expanding tests for MapBinder & adding support for OptionalBinder.)

Fixes #1715

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/guice/pull/1715 from kashike:fix/jakarta-multibinder 5d7226eaca
PiperOrigin-RevId: 528762998
2023-05-02 06:20:26 -07:00
Sam BerlinandGuice Team 104a113389 Optimize the way we skip sources of core Guice classes. Instead of building new binders by calling skipSources on-demand, we just skip all the expected sources by default. This significantly reduces some memory pressure when creating injectors (which was otherwise causing issues with the forthcoming CL to additionally bind jakarta Provider variants for MapBinder/Multibinder/OptionalBinder).
PiperOrigin-RevId: 528758521
2023-05-02 06:02:26 -07:00
Riley ParkandGuice Team a99b87af3d Implement and and or in Matcher directly
Fixes #1716
Fixes #1177

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/guice/pull/1716 from kashike:feature/and-or-matchers d1d63229b6
PiperOrigin-RevId: 528558457
2023-05-01 13:26:21 -07:00
Sam BerlinandGuice Team 36ff122d25 Rewrite jakarta singleton -> c.g.i Singleton for the SPI too.
PiperOrigin-RevId: 528546653
2023-05-01 12:41:34 -07:00
Sam BerlinandGuice Team 99d0e11294 Add a couple more missing @since tags.
PiperOrigin-RevId: 527669293
2023-04-27 13:36:37 -07:00
Sam BerlinandGuice Team 0c94a80454 Update @since vNext tags to @since 6.0
PiperOrigin-RevId: 527647564
2023-04-27 12:10:45 -07:00
Sam BerlinandGuice Team 5eff2eabd4 Add support for jakarta.inject to core Guice.
This does not add support for `toProvider(...)` to instances of `jakarta.inject.Provider` or classes/keys/typeLiterals of type `jakarta.inject.Provider`. See https://github.com/google/guice/issues/1383#issuecomment-1523410855 for details of the plans. The Guice 6.0 release will support `javax.inject` _and_ `jakarta.inject` (excluding `toProvider()` support for `jakarta.inject`), and the Guice 7.0+ release will remove the `javax.inject` references.

Further background on these issues:
 * https://github.com/google/guice/pull/1630
 * https://github.com/google/guice/issues/1679
 * https://github.com/google/guice/issues/1490
 * https://github.com/google/guice/issues/1383

PiperOrigin-RevId: 527349023
2023-04-26 12:55:35 -07:00
Hannes WellmannandGuice Team e17e8af8bd Completely remove OSGi Import-Package 'javax.annotation'
As suggested (and I assume also intended) in https://github.com/google/guice/pull/1173 this PR changes the configuration of the maven-bundle-plugin to completely remove the import of the package `javax.annotation`, which seems not to be required at runtime.

With PR https://github.com/google/guice/pull/1173 respectively https://github.com/google/guice/pull/1697 the OSGi package import of `javax.annotation;version="[3.0,4)"` was only changed to `javax.annotation`, i.e. the version range was removed.

Additionally update to latest maven-bundle-plugin 5.1.8.

Fixes #1708

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/guice/pull/1708 from HannesWell:removeJavaxAnnotation 968f4bcd71
PiperOrigin-RevId: 527092811
2023-04-25 15:33:46 -07:00
Sam BerlinandGuice Team 8edbe68a06 Don't immediately lookup the linked binding associated with @ImplementedBy. Instead, defer it like a normal bind(X.class).to(Y.class) does. This ensures that later bindings of Y are used.
Much thanks goes to @nineninesevenfour for their investigation (in #1650), which made fixing this much easier.

Fixes #700 and fixes #1650.

PiperOrigin-RevId: 527048972
2023-04-25 12:52:54 -07:00
Sam BerlinandGuice Team 4baf691855 Add a utility class for checking if Guice has enhanced a class (and returning the unenhanced version).
(Also changes the classname suffix to be a hex string instead of an int, which had previously included a leading negative sign, which was weird.)

Fixes #1340 & fixes #187.

PiperOrigin-RevId: 526291523
2023-04-22 09:19:43 -07:00
Ken WenzelandGuice Team 356f6ba30c Set correct bundle version of fragment host. Fixes #1050 & fixes #1049. Much thanks to @kenwenzel and @mcculls for their help figuring out the right incantation for this.
PiperOrigin-RevId: 526290216
2023-04-22 09:06:16 -07:00
Sam BerlinandGuice Team e68fab6524 Don't automatically create an EntityManager outside of a UnitOfWork, because it leads to leaks. Fixes #739, fixes #997, fixes #730, fixes #985, fixes #959, fixes #731. This also adds an optional Options to the JpaPersistModule constructor, if users wish to use the legacy behavior. This is a breaking change, but to a better default value. Users who want to keep the dangerous form can opt back in with the options.
PiperOrigin-RevId: 526106112
2023-04-21 12:24:37 -07:00
Andres ViedmaandGuice Team d882d5ed9f Don't wrap methods declared by Object in transactions. Fixes #958, fixes #788.
PiperOrigin-RevId: 526087773
2023-04-21 11:15:50 -07:00
Sam BerlinandGuice Team 2d78877e67 Recognize scoping annotations on concrete types also annotated with @ProvidedBy when using the @ProvidedBy as the provider.
Notably, this does *not* change things to allow scoping annotations on interfaces or abstract classes (even though theoretically we could, because the @ProvidedBy will be instantiating it). Scopes on abstract classes|interfaces will still throw an exception about the scope being misplaced.

Fixes #251 and fixes #1319.

PiperOrigin-RevId: 526009187
2023-04-21 05:41:01 -07:00
Jedediah SmithandGuice Team becce74bd9 Make requestInjection with an explicit type actually use the type. Fixes #1071.
PiperOrigin-RevId: 525898592
2023-04-20 17:57:36 -07:00
Thomas MeyerandGuice Team 0c43c8d013 Bump some plugin versions. Fixes #1026
PiperOrigin-RevId: 525828170
2023-04-20 13:06:43 -07:00
Clemens LiebandGuice Team 70ad639ea0 accomodate manually initiated rollbacks. Fixes #1137 & fixes #1136.
PiperOrigin-RevId: 525815800
2023-04-20 12:17:17 -07:00
Sebastian KuertenandGuice Team 7ed6624d70 Fix a number of Javadoc typos. Fixes #1078
PiperOrigin-RevId: 525805514
2023-04-20 11:39:35 -07:00
Stuart McCullochandGuice Team 94d28dd04b Mark JSR305 dependency as optional as it's not required at runtime (you only need it if you want to perform null analysis on the code). Fixes #1172
PiperOrigin-RevId: 525741584
2023-04-20 07:34:43 -07:00
Stuart McCullochandGuice Team d857befb8a Remove some lingering references to Java 6 (Guice 5+ requires Java 8). Fixes #1171.
PiperOrigin-RevId: 525564737
2023-04-19 15:21:45 -07:00
Stuart McCullochandGuice Team 410b83138c Minor updates to OSGi metadata. Fixes #1173
PiperOrigin-RevId: 525564484
2023-04-19 15:19:48 -07:00
Sam BerlinandGuice Team bccee9c2c1 Fix Guice's dependence on the system line separator by never using the system line separator and always using \n explicitly. (We were previously inconsistent: many places used \n, and many other places used %n with a formatter, which would end up being the system line separator.) This allows tests to pass on Windows, where the line separator is different. Also update tests to do a run with the windows line separator, to catch regressions. Fixes #1213.
PiperOrigin-RevId: 525558598
2023-04-19 14:56:48 -07:00
Chris PartonandGuice Team 3e21a13dfe Update the persist service to ignore multiple start/stop calls, so it matches its javadoc. Fixes #1214, fixes #972, fixes #598.
PiperOrigin-RevId: 525556346
2023-04-19 14:47:59 -07:00
Sam BerlinandGuice Team 5c95376766 Update documentation to elaborate on how hierarchical modules change the importance of otherwise unnecessary binding statements.
Closes #973, a documentation alternative to #1337.

PiperOrigin-RevId: 525497931
2023-04-19 11:09:04 -07:00
Sam BerlinandGuice Team c6b5cdfa94 Add truth's java8 extensions to the external bzl & maven build and update the version we use.
PiperOrigin-RevId: 525459640
2023-04-19 08:49:08 -07:00
Shane KennedyandGuice Team 9678847695 Remove references to Google Docs and instead point to the wiki when possible. Fixes #1556
PiperOrigin-RevId: 525231598
2023-04-18 13:14:49 -07:00
Vladimir SitnikovandGuice Team c3d8f51da6 Make PrivateModule#binder() non-final to allow binder customization in subclasses. Fixes #1569 & fixes #1525. (The primary use-case for this is to override binder() to always call skipSources, like many AbstractModule impls.)
PiperOrigin-RevId: 525231256
2023-04-18 13:12:34 -07:00
Sam BerlinandGuice Team 22dca18c8c Improve {Checked,Throwing}ProviderTest to allow exception types to be returned in any order from Method.getGenericExceptionTypes. Fixes #1603.
(This does not use the suggested code from the original PR, and does not attempt to change the `testManyMethods` method because we assume that repeated calls to `getDeclaredMethods` will always return the same order of methods. If that ever changes, we can deal with it then.)

PiperOrigin-RevId: 525220025
2023-04-18 12:35:49 -07:00
Sam BerlinandGuice Team 15d95bb199 Fix issues with recursive JIT loading that would lead to a deadlock and/or crash inside Guava's LoadingCache. The problem had to do with the fact that Guice eagerly stores uninitialized JIT bindings in an attempt to allow circular dependencies, and Guice also attempts to cleanup failed JIT bindings (to remove these uninitialized JIT bindings). The JIT binding cache was a guard against a recursive call back into the constructor's cache, but we were removing that guard.
We now only remove the guard if we aren't in the process of loading that JIT binding. The failed JIT binding is naturally cleaned up later on, as the existing & new tests attest to.

Fixes many issues:
 - Fixes #1633
 - Fixes #785
 - Fixes #1389
 - Fixes #1394

Many thanks to @swankjesse for the test-case added in #1389 that was helpful in diagnosing the problem, and to @PaulFridrick for the diagnoses in #1633.

PiperOrigin-RevId: 525219839
2023-04-18 12:35:23 -07:00
Sam BerlinandGuice Team f447cc4855 Bump junit to 4.13.2. Fixes #1585 & #1425.
PiperOrigin-RevId: 525219738
2023-04-18 12:31:10 -07:00
Sam BerlinandGuice Team 23c25d5e68 Bump struts2-core dependency to 2.5.30 & fix the struts2 test to work with the new version. Fixes #1624.
PiperOrigin-RevId: 525219685
2023-04-18 12:30:43 -07:00