Exceptor

From Ornithe Wiki
Revision as of 17:45, 12 August 2025 by Space Walker (talk | contribs) (add Exceptor page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Exceptor is a tool to patch exceptions in methods class attributes in Java class files. It takes in a Raven data file and applies those patches to a jar file.

Throws Clauses

The throws clause in a method declaration defines which exceptions can be thrown from within the method body. It is denoted by the throws key word and goes after the method parameter list before the opening bracket of the method body.

public void openPage(String address) throws URISyntaxException, IOException {
    ...
}

Methods Attributes

Java class files have a Methods attribute that contains entries for each method defined in a class. These entries contain values for the name and type descriptor of the method, but also for the exceptions that can be thrown by that method.

Obfuscators such as ProGuard may remove that value to shrink the jar file size. This is generally not a problem, since it does not affect the runtime behavior of a Java application. However, they do make a difference at compile time.

Usually, the Java compiler forces you to handle exceptions. However, if the throws clauses are missing for some methods, you can invoke them and not handle the exceptions, without any compile error. While this may sound nice, it will lead to unexpected behavior, bugs, and even crashes.

A more bothersome issue occurs when overriding methods where the throws clause is missing. You are not able to throw any exceptions in that method at all. The compiler will complain that the exceptions are not handled. However, adding a throws clause to your override is not possible, because the method you are overriding does not have one. The only solution is to catch the exception and throw a runtime exception instead.

The Methods Attribute

The Methods attribute of a class contains entries for all methods defined in that class. Each entry has four values:

  • method access: the access modifier of the method
  • method name: the name of the method
  • method type descriptor: the type descriptor of the method
  • method generic type signature: the generic type signature of the method
  • method exceptions: the internal names of all exceptions that can be thrown by the method

Exceptor

Exceptor patches the methods attributes in a jar using a Raven data file. It has the following features:

  • Setting the exceptions value in the methods attribute for existing methods.
  • Generating a Raven file from a given jar file.