Commit Graph
2074 Commits
Author SHA1 Message Date
Sam Berlin 0df8820181 set 6.0.0-rc2 release version in poms. 6.0.0-rc2 2023-05-04 17:48:25 -04: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
Sam BerlinandGuice Team f67f9d19c2 Bump spring dependency to 5.3.18. Fixes #1620.
PiperOrigin-RevId: 525219514
2023-04-18 12:28:11 -07:00
Sam BerlinandGuice Team 8cf8c62a29 Prevent endless loop in lock cycle detection. The following scenario would previously fail:
* T1: Enter `lockOrDetectPotentialLocksCycle`:
    - Lock CAF.class, add itself to `lockThreadIsWaitingOn`, unlock CAF.class
    - Lock the cycle detecting lock (CDL)
    - Lock CAF.class, mark itself as `lockOwnerThread`, remove itself from `lockThreadIsWaitingOn`
    - Exit `lockOrDetectPotentialLocksCycle`
 * T1: Re-enter `lockOrDetectPotentialLocksCycle`:
    - Lock CAF.class, add itself to `lockThreadIsWaitingOn`, unlock CAF.class
 T2: Enter `lockOrDetectPotentialLocksCycle`
    - Lock CAF.class, invoke `detectPotentialLocksCycle`.

At this point, `detectPotentialLocksCycle` will now loop forever, because the `lockOwnerThread` is also in `lockThreadIsWaitingOn`. During the course of looping forever, it will OOM, because it's building up an in-memory structure of what it thinks are cycles.

The solution is to avoid the re-entrant T1 from adding itself to `lockThreadIsWaitingOn` if it's already the `lockOwnerThread`. It's guaranteed that it won't relinquish the lock concurrently, because it's the exact same thread that owns it.

Fixes #1635 and Fixes #1510

PiperOrigin-RevId: 525182219
2023-04-18 10:18:59 -07:00
Stuart McCullochandGuice Team 3399615520 Use Lookup.class as the base when retrieving trusted lookup because we know that's where the field is declared.
Fixes #1673
Fixes #1672

PiperOrigin-RevId: 524835342
2023-04-17 06:59:10 -07:00
Sam BerlinandGuice Team 5c37cd9662 Update LineNumbers to ignore all kinds of exceptions when reading classes with ASM, so Guice is less finicky about the precise .class version & ASM version. A while ago I had tried to do this by ignoring UnsupportedOperationException, but per https://github.com/google/guice/issues/1654, ASM doesn't always throw UOE.
This change will log a single failure when Guice encounters an exception while reading classfiles and warn that ASM may be out of date.

The consequences of this failing _all_ line number reading (due to, say, an accidental bug introduced while parsing classfiles) is that Guice won't emit line numbers for bind statements in modules (as binding source locations). A number of other tests would fail in that scenario, warning us that something is off.

PiperOrigin-RevId: 524387180
2023-04-14 14:29:14 -07:00
Kurt SeebauerandGuice Team d98a4de1ea prevent NullPointerException if contextPath is null
Fixes #1656
Fixes #1655

PiperOrigin-RevId: 524374664
2023-04-14 13:38:51 -07:00
Sylwester LachiewiczandGuice Team 65c38f88e6 Upgrade ASM from 9.1 to 9.5 to support Java 21
Fixes #1671
Fixes #1657
Fixes #1654
Fixes #1521
Fixes #1256

PiperOrigin-RevId: 524365072
2023-04-14 12:58:49 -07:00
Guice TeamandGuice Team 06e8bb1ea1 Clarify that Multibinder elements need not be distinct if permitDuplicates() is specified.
PiperOrigin-RevId: 517978849
2023-03-20 08:43:58 -07:00
Guice TeamandGuice Team f26a731e3d Fix typo in jdoc.
PiperOrigin-RevId: 516590803
2023-03-14 11:54:26 -07:00
Guice TeamandGuice Team 4a8965a899 Automated visibility attribute cleanup.
PiperOrigin-RevId: 505840946
2023-01-30 17:17:48 -08:00
Guice TeamandGuice Team 9ed45ab2c6 Open-source @Keep on Guice annotations.
PiperOrigin-RevId: 503916049
2023-01-23 01:19:00 -08:00
Guice TeamandGuice Team 294065ccc1 All testing uses Mockito instead of EasyMock.
PiperOrigin-RevId: 498600399
2022-12-30 09:45:27 -08:00