Removal is how PreEmptive Protection™ DashO™ removes code and metadata your application doesn't need. It covers three features:
- Removing unused classes and members
- Removing attributes the compiler generates
- Removing specific classes explicitly
Removal reduces the size of your application and helps protect it. Some debug and compiler-generated attributes give attackers extra insight into your application.
This article explains how Removal works. To configure it, see Configuring Removal. To remove calls to specific methods, such as logging calls, see Method Call Removal.
Removing Unused Classes and Members
DashO follows your Entry Points to find which classes and members your code uses. It treats any class, method, or field it doesn't reach as unused, and removes it.
You set Removal separately for classes and for members (methods and fields):
| Option | What DashO removes | Typically used for |
| Remove | All unused classes or members. | Applications |
| Remove if not public | Only unused classes or members that aren't public or protected . |
Libraries with public APIs. Library Entry Points achieve the same goal. |
| Do not remove | Nothing. | — |
Exclusions
Exclude classes and members you want DashO to keep, even if they appear unused. See Exclude Items from Removal.
Reflection
If your code accesses a class or member only through reflection, DashO can't always tell that it's used. You have these options:
- Add the classes and members as Entry Points, or exclude them from Removal. This is generally the more reliable option.
- Select Determine Reflected Classes on the Input > Options page. DashO then tries to find simple reflection-based access to classes during Renaming and Removal analysis.
Removing Attributes
DashO removes the debug information and other attributes you select. Some of this information is required when you compile against a library, or by applications that use reflection. Remove only what your application doesn't need at runtime.
Debug Information
| Friendly Name (Used in GUI) | Attribute Name (used in project file) | Description |
|---|---|---|
| Source File | SourceFile |
The name of the file that contains a class's source code. |
| Source Directory | SourceDir |
The directory that contains the source file. Uncommon. |
| Source Debug Extension | SourceDebugExtension |
Extended, tool-specific debug information. |
| Line Number Table | LineNumberTable |
Maps bytecode instructions to line numbers in the original source file. |
| Local Variables | LocalVariableTable |
The names and types of local variables while a method runs. |
| Local Variable Types | LocalVariableTypeTable |
The type parameters of local variables with generic types. |
Debuggers use most of this information. To get stack traces with meaningful line numbers, keep Line Number Table and Source File.
Additional Attributes
The Java compiler also stores metadata about classes and their members in attributes. Removing what your application doesn't need reduces the size of your class files, and may improve protection, because some of this information gives attackers insight into your software.
| Friendly Name (Used in GUI) | Attribute Name (used in project file) | Description |
|---|---|---|
| Exceptions | Exceptions |
The checked exceptions a method may throw. |
| Signature | Signature |
The signature of a class, method, or field that takes type parameters or uses a parameterized type. |
| Deprecated | Deprecated |
Marks a class, interface, method, or field as superseded. When enabled, DashO removes both the JVM Deprecated attribute and the java.lang.Deprecated annotation. For more information, see Deprecation Metadata. |
| Synthetic | Synthetic |
Marks a class member that doesn't appear in source code. |
| Enclosing Method | EnclosingMethod |
The enclosing method of an anonymous class. |
| Inner Classes | InnerClasses |
Relationships between inner and outer classes. |
| Visible Annotations | RuntimeVisibleAnnotations |
Annotations on a class, method, or field that are visible through reflection, such as @Deprecated, @FunctionalInterface, and @SafeVarargs. |
| Invisible Annotations | RuntimeInvisibleAnnotations |
Annotations on a class, method, or field that aren't visible through reflection. |
| Visible Parameter Annotations | RuntimeVisibleParameterAnnotations |
Annotations on method parameters that are visible through reflection. |
| Invisible Parameter Annotations | RuntimeInvisibleParameterAnnotations |
Annotations on method parameters that aren't visible through reflection. |
| Annotation Default | AnnotationDefault |
Default values for annotation elements. |
| Method Parameters | MethodParameters |
The names of a method's parameters. |
| Unknown Attributes | Unknown |
All other attribute types. |
Deprecation Metadata
Java records deprecation in two forms: the JVM Deprecated attribute and the java.lang.Deprecated annotation. When you enable Deprecated removal, DashO removes both by default.
DashO removes only the java.lang.Deprecated annotation. Other runtime-visible and runtime-invisible annotations stay unchanged.
If your project still needs the annotation, enable compatibility mode with the preserveDeprecatedAnnotation option of the <attributes> element in your project file:
preserveDeprecatedAnnotation |
JVM Deprecated attribute
|
java.lang.Deprecated annotation
|
false (default) |
Removed | Removed |
true |
Removed | Preserved |
To remove the JVM Deprecated attribute but keep the java.lang.Deprecated annotation, set preserveDeprecatedAnnotation to true:
<attributes
types="Deprecated"
preserveDeprecatedAnnotation="true"/>Removing Classes
If your inputs contain classes you don't want in the output, such as unit tests or samples, configure DashO to remove them entirely. DashO removes these classes even if you also exclude them from Removal. For more information, see Remove Specific Classes.
Examples and Use Cases
Choose a Removal Configuration
| Scenario | Approach |
| You protect an application. | Set unused classes and members to Remove. |
| You protect a library with a public API. | Use Remove if not public, or define Library Entry Points. |
| You need readable stack traces from production. | Keep Line Number Table and Source File. |
| Your inputs include unit tests or samples. | Remove those classes explicitly. |
| Your code loads classes through reflection. | Add them as Entry Points, or exclude them from Removal. |
Limitations and Troubleshooting
| Limitation or issue | Details |
| Removal is unavailable. | Your project uses Android Mode, where R8 handles removal. Enable R8. |
| Code accessed through reflection is missing at runtime. | DashO can't always detect reflection, and never detects reflection-based access to methods or fields. Add the items as Entry Points, or exclude them from Removal. |
| The application fails at runtime after you remove specific classes. | Another input class references a removed class. Stop removing it, or remove the references. |
| An excluded class is still removed. | It also matches a rule for removing specific classes. Those rules override exclusions. |
Code that reads the java.lang.Deprecated annotation stops working. |
Deprecated removal also removes the annotation. Set preserveDeprecatedAnnotation="true". For more information, see Deprecation Metadata. |
| Stack traces have no line numbers. | Line Number Table or Source File was removed. Keep both. |
| Type annotations are missing. | DashO always removes them. You can't disable this. |