Commit a74df1a
authored
fix(geolocation): replace setClient with Lookup-based factory SPI (#24259)
## Summary
- Promotes `GeolocationClient` to a public SPI and adds a
`GeolocationClientFactory` extension point resolved through
`com.vaadin.flow.di.Lookup`.
- `Geolocation` queries the factory at construction time and falls back
to the built-in browser-backed client when none is registered.
- `setClient` is retained as a package-private in-JAR seam for
flow-server's own tests; external test drivers and native bridges
register a factory via `META-INF/services`.
## Why
Follow-up to #24211. The `setClient` seam (originally package-private)
breaks under split-classloader topologies (Quarkus, OSGi, JPMS): the JVM
scopes runtime packages by classloader, so a class in `flow-server.jar`
and one in an external JAR with the same package name end up in
**different runtime packages** when their JARs load through different
classloaders. Cross-JAR package-private access then throws
`IllegalAccessError` at class definition time. Reproduced locally and in
CI on browserless-test PR #51:
```
java.lang.IllegalAccessError: class com.vaadin.flow.component.geolocation.BrowserlessGeolocationClient
cannot access its superinterface com.vaadin.flow.component.geolocation.GeolocationClient
(BrowserlessGeolocationClient is in unnamed module of loader QuarkusClassLoader @34eb5d01;
GeolocationClient is in unnamed module of loader QuarkusClassLoader @272778ae)
```
`Lookup` is classloader-aware and explicitly designed for this kind of
pluggable SPI — it's the canonical Flow pattern (`InstantiatorFactory`,
`RoutePathProvider`, `ResourceProvider`, `StaticFileHandlerFactory`,
`BrowserLiveReloadAccessor`).
## Changes
- `GeolocationClient` → `public interface` with proper SPI Javadoc (no
longer "framework internal").
- `GeolocationClientFactory` (new) → `public interface`, resolved via
`Lookup`; documents the use cases (in-memory test drivers; native
bridges in Cordova/Electron/Capacitor shells).
- `Geolocation` constructor calls `resolveClient(ui)` → looks up a
factory via `VaadinService.getCurrent()` →
`Lookup.lookup(GeolocationClientFactory.class)`; falls back to `new
BrowserGeolocationClient(ui, seed)` when no factory is registered.
- `setClient` stays package-private — flow-server's own tests use it;
external code goes through `Lookup`.
- `BrowserGeolocationClient` Javadoc updated to mention it's the
no-factory default.
- `GeolocationClientSeamTest` now exercises both the public
Lookup-factory path and the in-package `setClient` seam.
No `META-INF/services` file is shipped from flow-server: production has
no factory and uses the fallback. Implementations live in external JARs
(e.g. browserless-test-shared).
## Test plan
- [x] `mvn test -pl :flow-server -Dtest='*Geolocation*'` — 38/38 pass
locally.
- [x] No `@SuppressWarnings("NullAway")` introduced; constructor assigns
the `client` field directly.
- [x] Local end-to-end verification with browserless-test patched to
register a factory: Quarkus suite that previously threw
`IllegalAccessError` now passes (junit6 21/21, quarkus 11/11, including
`QuarkusBrowserlessBaseClassTest` and `QuarkusUnitSecurityTest` that
were failing).
- [ ] Reviewer to confirm SPI shape (factory vs. direct service) is
acceptable for Flow's public API surface.
cc @mcollovati1 parent 724cc06 commit a74df1a
5 files changed
Lines changed: 157 additions & 28 deletions
File tree
- flow-server/src
- main/java/com/vaadin/flow/component/geolocation
- test/java/com/vaadin/flow/component/geolocation
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
Lines changed: 42 additions & 16 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
116 | 119 | | |
117 | 120 | | |
118 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
119 | 127 | | |
120 | 128 | | |
121 | 129 | | |
122 | 130 | | |
123 | 131 | | |
124 | 132 | | |
125 | | - | |
126 | | - | |
127 | 133 | | |
128 | 134 | | |
129 | 135 | | |
| |||
133 | 139 | | |
134 | 140 | | |
135 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
136 | 151 | | |
137 | 152 | | |
138 | 153 | | |
139 | 154 | | |
140 | 155 | | |
141 | | - | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
142 | 176 | | |
143 | 177 | | |
144 | 178 | | |
| |||
296 | 330 | | |
297 | 331 | | |
298 | 332 | | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | 333 | | |
306 | | - | |
307 | | - | |
308 | | - | |
| 334 | + | |
309 | 335 | | |
310 | | - | |
| 336 | + | |
311 | 337 | | |
312 | 338 | | |
313 | | - | |
| 339 | + | |
314 | 340 | | |
315 | | - | |
316 | | - | |
| 341 | + | |
| 342 | + | |
317 | 343 | | |
318 | 344 | | |
319 | 345 | | |
Lines changed: 35 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
36 | 44 | | |
37 | 45 | | |
38 | 46 | | |
39 | | - | |
| 47 | + | |
40 | 48 | | |
41 | 49 | | |
42 | 50 | | |
43 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
| |||
49 | 61 | | |
50 | 62 | | |
51 | 63 | | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
52 | 73 | | |
53 | 74 | | |
54 | 75 | | |
| |||
57 | 78 | | |
58 | 79 | | |
59 | 80 | | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
60 | 86 | | |
61 | 87 | | |
62 | 88 | | |
63 | 89 | | |
64 | 90 | | |
65 | 91 | | |
66 | 92 | | |
| 93 | + | |
| 94 | + | |
67 | 95 | | |
68 | 96 | | |
69 | 97 | | |
70 | 98 | | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
76 | 103 | | |
77 | 104 | | |
78 | 105 | | |
| |||
91 | 118 | | |
92 | 119 | | |
93 | 120 | | |
| 121 | + | |
| 122 | + | |
94 | 123 | | |
95 | 124 | | |
96 | 125 | | |
| |||
Lines changed: 52 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
Lines changed: 25 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| 29 | + | |
| 30 | + | |
28 | 31 | | |
| 32 | + | |
29 | 33 | | |
30 | 34 | | |
31 | 35 | | |
| |||
36 | 40 | | |
37 | 41 | | |
38 | 42 | | |
39 | | - | |
40 | | - | |
41 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
42 | 48 | | |
43 | 49 | | |
44 | 50 | | |
| |||
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
56 | 78 | | |
57 | 79 | | |
58 | 80 | | |
| |||
0 commit comments