# Class PiiScrubber

java.lang.Object
com.codename1.crash.PiiScrubber

public class PiiScrubber extends Object

Default PII scrubber for `CrashProtection` uploads. Designed to be subclassed: override `scrubMessage(String)` or `scrubFrame(String, String)` to extend the behaviour, then register the subclass with `CrashProtection.setScrubber(PiiScrubber)`.

Default behaviour applied to exception message strings only:

1. Emails partially redacted: the local part is truncated to its first three characters followed by `***`, the domain is preserved. Example: `johndoe@example.com` becomes `joh***@example.com`.
2. Runs of six or more consecutive digits are replaced with `[num]`, catching phone numbers, long IDs, etc.
3. URLs are NOT scrubbed (they routinely carry useful debugging context; if a particular app embeds tokens in URLs it can opt-in to URL scrubbing by overriding this class).

Stack frames are not scrubbed by default. Class and method names do not carry PII; subclasses that emit synthetic frames containing user data may override `scrubFrame(String, String)`.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PiiScrubber()`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected static String`
  `scrubDigitRuns(String s)`
  Replaces every run of six or more consecutive ASCII digits with the literal token `[num]`.
  `protected static String`
  `scrubEmails(String s)`
  Replaces all occurrences of an email-like substring with the form `<first-three>***@<domain>`.
  `String`
  `scrubFrame(String className, String methodName)`
  Scrubs PII from a single stack frame.
  `String`
  `scrubMessage(String message)`
  Scrubs PII from a free-form message, typically an exception message.

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### PiiScrubber

    public PiiScrubber()

- ## Method Details

  - ### scrubMessage

    public String scrubMessage(String message)

    Scrubs PII from a free-form message, typically an exception message. The default implementation applies email partial redaction and long-digit-run masking.

    ###### Parameters

    - `message`: original message; may be `null`.

    ###### Returns

    scrubbed message, or `null` if `message` is `null`.

  - ### scrubFrame

    public String scrubFrame(String className, String methodName)

    Scrubs PII from a single stack frame. Default implementation returns the original method name unchanged.

    ###### Parameters

    - `className`: fully-qualified class name of the frame.
    - `methodName`: method name of the frame.

    ###### Returns

    the (possibly modified) method name to upload.

  - ### scrubEmails

    protected static String scrubEmails(String s)

    Replaces all occurrences of an email-like substring with the form `<first-three>***@<domain>`. Local parts shorter than three characters are not padded; the original prefix is preserved and followed by `***`. The domain (including TLD) is preserved verbatim.

    This implementation is character-driven rather than regex-based to stay compatible with the Java 5 source level enforced by the core framework module.

  - ### scrubDigitRuns

    protected static String scrubDigitRuns(String s)
    Replaces every run of six or more consecutive ASCII digits with the literal token `[num]`.