[Paper Review] NPEFix: Automatic Runtime Repair of Null Pointer Exceptions in Java
NPEFix is a dynamic, code transformation-based approach that automatically repairs null pointer exceptions (NPEs) at runtime in Java by applying 9 alternative execution strategies—such as injecting default objects or skipping problematic code—when a harmful NPE is detected. It successfully repairs 10 out of 11 real-world field bugs and 318 out of 519 seeded NPEs, with method-level skipping proving the most effective strategy.
Null pointer exceptions, also known as null dereferences are the number one exceptions in the field. In this paper, we propose 9 alternative execution semantics when a null pointer exception is about to happen. We implement those alternative execution strategies using code transformation in a tool called NPEfix. We evaluate our prototype implementation on 11 field null dereference bugs and 519 seeded failures and show that NPEfix is able to repair at runtime 10/11 and 318/519 failures.
Motivation & Objective
- To address the pervasive problem of null pointer exceptions (NPEs), the top cause of crashes in Java and C-based systems, by enabling automatic runtime repair instead of static prevention.
- To design and evaluate a set of 9 runtime repair strategies that provide alternative execution semantics when a null dereference is imminent.
- To implement a prototype tool, NPEFix, using source code transformation to insert detection and repair hooks at runtime.
- To empirically evaluate the effectiveness of these strategies on real-world field bugs and artificially seeded null dereference failures.
Proposed method
- NPEFix uses source code transformation to insert runtime checks that detect potentially harmful null dereferences before they trigger exceptions.
- It maintains a dynamic stack model of try-catch blocks to distinguish between caught and uncaught null pointer exceptions, focusing only on uncaught ones as harmful.
- Nine distinct repair strategies are implemented: four for object injection (local/global, reuse/new), four for skipping (statement/method), and one for returning a default value.
- The tool configures and activates these strategies dynamically at runtime based on the context of the null dereference.
- Code transformations are applied to Java source code to instrument detection logic and hook into the repair mechanisms.
- Evaluation is conducted on 11 real field NPEs from open-source projects and 519 seeded NPEs by removing all null checks and running test suites.
Experimental results
Research questions
- RQ1Can automatic runtime repair of null pointer exceptions be achieved using configurable execution strategies that avoid crashing the application?
- RQ2Which of the nine proposed repair strategies—object injection, skipping statements, or skipping methods—is most effective in practice?
- RQ3How effective is the NPEfix approach in repairing real-world, field-reported null pointer exceptions compared to artificially seeded failures?
- RQ4To what extent do repair strategies lead to subsequent runtime errors, indicating potential instability in the repaired state?
Key findings
- NPEFix successfully repairs 10 out of 11 real-world field-reported null pointer exceptions, demonstrating strong practical applicability.
- In the seeded failure evaluation, NPEfix repairs 318 out of 519 null dereference failures, achieving a repair rate of 61.3%.
- Method-level skipping is the most effective strategy, repairing 9 out of 11 field bugs and 210 out of 519 seeded failures.
- The use of local or global injection of existing compatible objects is effective, with global injection showing broader applicability across diverse codebases.
- The strategy of injecting a newly created object (S2a/S2b) provides a viable fallback when no compatible existing object is available.
- Despite repair success, 104 out of 519 seeded failures led to subsequent runtime errors after repair, indicating potential state instability in some cases.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.