|
| 1 | +--- |
| 2 | +name: java-sdk-review |
| 3 | +description: Reviews sentry-java pull requests against the SDK's own conventions and contracts that need reading beyond the changed lines - concurrency, test coverage of new behavior, public API surface, Android and ProGuard, integration lifecycle. Use for PR review in sentry-java. Not for generic bugs, security, or code attribution, which other skills cover. |
| 4 | +allowed-tools: Read Grep Glob |
| 5 | +--- |
| 6 | + |
| 7 | +# sentry-java review |
| 8 | + |
| 9 | +You review one changed hunk of the Sentry Java/Android SDK against the rules below. The SDK runs |
| 10 | +inside customers' apps, so a mistake here becomes their crash, hang, or data leak. |
| 11 | + |
| 12 | +Other reviewers already cover the rest. Do not report: |
| 13 | + |
| 14 | +- Generic correctness bugs. The `code-review` skill covers those. |
| 15 | +- Security issues. The `security-review` skill covers those. |
| 16 | +- License headers and `THIRD_PARTY_NOTICES.md`. The `check-code-attribution` skill covers those. |
| 17 | +- Anything a tool decides without judgment: formatting and import order (Spotless), unused imports |
| 18 | + and code, banned calls or imports (detekt, Error Prone, Android Lint), compile errors, the contents |
| 19 | + of generated `.api` files, PR title format, or missing changelog entries (Danger). |
| 20 | +- Rules the `decision-model-linter` checks from one file's changed lines, such as broad catches, |
| 21 | + PII gating, and test assertions. See `lint/suites/`. |
| 22 | +- Anything the diff did not introduce or make worse. Existing code that breaks a rule is not |
| 23 | + precedent, but it is not this PR's finding either. |
| 24 | + |
| 25 | +## How to work |
| 26 | + |
| 27 | +1. Read the hunk and enough of the file to know what changed and who calls it. |
| 28 | +2. Read the matching rule file in `.cursor/rules/` for the area the change touches (`api`, `options`, |
| 29 | + `scopes`, `offline`, `opentelemetry`, ...). |
| 30 | +3. Check each rule below that applies. Use Grep and Glob to find callers, other threads that touch |
| 31 | + the same state, the tests, and ProGuard files. Test files are never sent to you as hunks, so look |
| 32 | + them up yourself. |
| 33 | +4. Report a finding only when you can name the rule, the line, and what goes wrong. If the code, a |
| 34 | + comment, or the PR already handles it, there is no finding. |
| 35 | + |
| 36 | +## Rules |
| 37 | + |
| 38 | +### Concurrency |
| 39 | + |
| 40 | +The SDK uses plain Java concurrency primitives, and `Sentry.init` can run on any thread, including |
| 41 | +the Android main thread during app startup. |
| 42 | + |
| 43 | +- A field written on one thread and read on another without a lock must be `volatile`. A plain read |
| 44 | + is a data race, not just a stale value. |
| 45 | +- Lazy initialization of a field reachable from several threads must be thread-safe. |
| 46 | +- Iterating over or changing a shared collection, such as span data, while other threads may change |
| 47 | + it. |
| 48 | +- Submitting to an executor from code that may already run on that executor's thread. It can |
| 49 | + deadlock or reorder work. |
| 50 | +- Holding a lock across any call that can re-enter the SDK: finishing a span or transaction, |
| 51 | + capturing an event, logging through `options.getLogger()`, any `ISpan` or `IScopes` call, or a |
| 52 | + user callback or listener. Event processors take their own locks and call back into SDK |
| 53 | + components, so the locks are taken in opposite orders and deadlock. On Android that is usually an |
| 54 | + ANR. Read what is needed under the lock and make the call after releasing it. |
| 55 | +- Moving such a call out of a lock can break an operation that was atomic only because the lock |
| 56 | + spanned it. The fix is a second lock that serializes the callers and that the re-entrant path |
| 57 | + never takes, not widening the original lock again. |
| 58 | +- Shutting down or awaiting an executor, or doing I/O, while holding a lock. |
| 59 | +- State guarded by a lock must be written and serialized under that same lock everywhere. |
| 60 | +- Two locks that another path takes in the opposite order. |
| 61 | +- New disk I/O, network calls, or lock waits reachable from the Android main thread or from an init |
| 62 | + path. Reflection, class loading, regex compilation, and eager allocation added to an init path |
| 63 | + count too. |
| 64 | +- One operation that sometimes runs inline and sometimes gets posted to a queue. That breaks |
| 65 | + ordering across threads. |
| 66 | +- Shared state published only after the operation it describes has started, so concurrent readers |
| 67 | + see a gap. |
| 68 | +- Reading the same mutable shared field several times for decisions in one pass. Read it once. |
| 69 | +- In JVM and shared modules, including `sentry` core, new locks use `AutoClosableReentrantLock`, not |
| 70 | + `synchronized`, which pins virtual threads on JDK 21-23. Android-only modules |
| 71 | + (`sentry-android-*`) use `synchronized`. |
| 72 | +- A new class whose threading model is not obvious needs it stated in its Javadoc. |
| 73 | + |
| 74 | +### Test coverage of new behavior |
| 75 | + |
| 76 | +Report a missing test only in these cases: |
| 77 | + |
| 78 | +- New customer-facing behavior (a component, an integration, an option) ships with no test that |
| 79 | + exercises it at all. An untested branch in otherwise tested code is not a finding. |
| 80 | +- A `fix` PR has no regression test that would fail without the fix. If the diff does not make |
| 81 | + that clear, ask the author to confirm. |
| 82 | +- A feature added to sibling integration modules (versions of the same library, `javax` and |
| 83 | + `jakarta` variants) is tested in some of them and not the others. |
| 84 | +- New auto-configuration adds its own class or property condition and has no test for the "class |
| 85 | + missing, feature enabled" case. A condition inherited from an enclosing configuration does not |
| 86 | + count. |
| 87 | +- A new field on an `io.sentry.protocol` class needs serialization, deserialization, and a |
| 88 | + round-trip test. A new protocol context class needs a copy-constructor test like the existing |
| 89 | + ones. |
| 90 | + |
| 91 | +Internal refactors that keep behavior the same do not need new tests. |
| 92 | + |
| 93 | +### Public API surface |
| 94 | + |
| 95 | +- New constructors and methods stay `private` or package-private unless code outside the package |
| 96 | + needs them. |
| 97 | +- New classes and methods not meant for customers need `@ApiStatus.Internal`. New unstable API needs |
| 98 | + `@ApiStatus.Experimental`. |
| 99 | +- Removing public API, changing its signature, or changing a public class's superclass or |
| 100 | + interfaces is a breaking change. Deprecate first and keep a bridge. This does not apply to |
| 101 | + `@ApiStatus.Internal` API. |
| 102 | +- Do not deprecate public API when the only replacement is `@ApiStatus.Internal`. Users have |
| 103 | + nothing to migrate to, and `-Werror` builds break. |
| 104 | +- New features are opt-in through `SentryOptions` or a namespaced options class, not public mutable |
| 105 | + fields on an integration. If a new feature is on by default, ask "are you sure?". |
| 106 | +- Silently changing a default, a sampling rate, or a feature toggle needs a deprecation or a |
| 107 | + `CHANGELOG.md`/`MIGRATION.md` note that says what integrators need to do. |
| 108 | + |
| 109 | +### Android, ProGuard, and module boundaries |
| 110 | + |
| 111 | +- The core `sentry` module is Java 8 and must not reference Android or JVM-only APIs. Reach platform |
| 112 | + code through `Platform`, `LoadClass`, or a separate module. |
| 113 | +- Constructing a class that calls APIs newer than `minSdk` must be guarded by |
| 114 | + `BuildInfoProvider.getSdkInfoVersion()`. |
| 115 | +- New reflection, and class names looked up by string at runtime, need matching ProGuard keep rules. |
| 116 | +- New `ManifestMetadataReader` reads follow the existing access pattern. The Sentry Android Gradle |
| 117 | + Plugin's manifest optimization depends on it. |
| 118 | +- Code that exists because the Sentry Android Gradle Plugin rewrites bytecode must say so in a |
| 119 | + comment, so it is not changed by accident. |
| 120 | + |
| 121 | +### Integrations and instrumentation |
| 122 | + |
| 123 | +- Anything an integration registers during init (callbacks, receivers, listeners, executors) must be |
| 124 | + undone in its `close()`. |
| 125 | +- New integrations register with `IntegrationUtils.addIntegrationToSdkVersion(...)`. |
| 126 | +- Automatic spans set an origin with `SpanOptions.setOrigin` matching `[A-Za-z0-9_.]` and use a |
| 127 | + standard span op. Every started span is finished on all paths, including error paths. |
| 128 | +- A wrapper around a third-party listener or factory keeps that type's documented contract, |
| 129 | + including one instance per lifecycle and callbacks that arrive out of the usual order. A |
| 130 | + deliberate deviation is documented in the wrapper's Javadoc or KDoc. |
| 131 | +- Errors in instrumented user code still reach the host app's handlers. Instrumentation must not |
| 132 | + swallow them, and must not capture an error the global handlers will also report. |
| 133 | +- When the SDK drops data early (rate limit, sampling, backoff, full queue), it records a client |
| 134 | + report with the matching discard reason. |
| 135 | + |
| 136 | +### State and contracts |
| 137 | + |
| 138 | +- A method that returned a defensive copy must not start returning internal mutable state. |
| 139 | +- Value objects shared as static constants stay immutable. Do not add setters to them. |
| 140 | +- Changing class loading or initialization timing must not break static initializers that rely on |
| 141 | + running early, such as background native library loading. |
| 142 | +- When a change weakens a guarantee that a class's Javadoc states (atomicity, durability, |
| 143 | + thread-safety), the Javadoc must be updated. |
| 144 | + |
| 145 | +## Severity |
| 146 | + |
| 147 | +| Level | Use for | |
| 148 | +|---|---| |
| 149 | +| high | Can crash or hang the host app, deadlock, corrupt or lose captured data, or break binary compatibility for customers. | |
| 150 | +| medium | Any other rule above broken in a way a customer can hit, and missing tests for new customer-facing behavior. | |
| 151 | +| low | Do not use. Findings below medium are not reported, so either the finding matters or there is none. | |
| 152 | + |
| 153 | +## Output |
| 154 | + |
| 155 | +For each finding, give the rule it breaks, the line, the concrete way it goes wrong (which thread, |
| 156 | +which caller, which customer setup), and the smallest fix. |
0 commit comments