Class CrashProtection

java.lang.Object
com.codename1.crash.CrashProtection

public final class CrashProtection extends Object

Crash protection: captures unhandled exceptions, scrubs PII, persists each crash to Storage immediately, and uploads to the Codename One cloud crash service when enabled.

Quick start:

// In your start() method, after Display has initialised:
CrashProtection.install();
// Once your app has obtained user consent (e.g. from a settings
// screen) flip this on. The default is off so no data leaves the
// device until the developer explicitly enables uploads.
CrashProtection.setEnabled(true);

Pluggable PII scrubbing: override PiiScrubber and register your subclass via setScrubber(PiiScrubber) to extend the default redaction rules. The default scrubber masks the local part of email addresses (keeping the first three characters and the full domain) and replaces runs of six or more digits with [num].

The endpoint URL is fixed and cannot be modified by the application. Crash uploads are accepted only for Pro-tier (or higher) accounts for builds produced by the Codename One cloud build server within the last 30 days; out-of-tier or stale builds are silently dropped by the server.

This runs in parallel with the legacy Log.bindCrashProtection path; both can be installed in the same app without conflict.

  • Method Details

    • install

      public static void install()

      Installs the crash protection hooks. Idempotent: calling more than once has no effect. Does nothing on the simulator (matches the legacy Log.bindCrashProtection behaviour).

      Side effect: any crashes previously persisted to storage but not yet uploaded will be drained in the background if uploads are currently enabled.

    • isEnabled

      public static boolean isEnabled()
      Returns:
      true if crash uploads are enabled. Default is false.
    • setEnabled

      public static void setEnabled(boolean enabled)
      Enables or disables crash uploads. When transitioning from off to on, any crashes buffered in storage are drained in the background. The toggle persists across launches.
    • setScrubber

      public static void setScrubber(PiiScrubber s)
      Replaces the active PII scrubber. Subclass PiiScrubber to extend or replace the default redaction rules.
    • getScrubber

      public static PiiScrubber getScrubber()
    • capture

      public static void capture(Throwable t)
      Manually report an exception. The crash is persisted to storage first and then uploaded if uploads are enabled. Stack frames are captured from the throwable.