SpoonLabs / npefix

Open-science code of the program repair tool described in "Dynamic Patch Generation for Null Pointer Exceptions Using Metaprogramming" (SANER'17)
https://hal.archives-ouvertes.fr/hal-01419861/document
14 stars 9 forks source link

NpeFix generates an impossible patch, `return null` in a constructor #8

Open monperrus opened 6 years ago

monperrus commented 6 years ago

Good news, we have a patch in repairnator!

+++ /StreamDefinitionController.java
@@ -379,2 +379,5 @@

+           if (StreamDefinitionController.this.streamService == null) {
+               return null;
+           }
            streamDeploymentStates = StreamDefinitionController.this.streamService

But this patch is impossible, because it is in a constructor, and return null is impossible in a constructor.

tdurieux commented 6 years ago

it is probably an error in the patch generator. I need more info, the complete json result will be useful

surli commented 6 years ago

It's not formatted at all, but here it is: https://github.com/Spirals-Team/librepair-experiments/blob/spring-cloud-spring-cloud-dataflow-284933348-20171008-064257_bugonly/repairnator.npefix.results

tdurieux commented 6 years ago

NPEFix does not generate correctly the patch. The strategy is a return VOID in a constructor, it means that it has to wrap with an if not null the end of the constructor.

Like this:

+++ /StreamDefinitionController.java
@@ -379,2 +379,5 @@

+           if (StreamDefinitionController.this.streamService != null) {
+               streamDeploymentStates = StreamDefinitionController.this.streamService
+           }
-           streamDeploymentStates = StreamDefinitionController.this.streamService
monperrus commented 6 years ago

This is impossible in this case, the compiler complains because because the field streamDeploymentStates may be uninitialized.

tdurieux commented 6 years ago

True, I forgot that we remove final modifier...

+++ /StreamDefinitionController.java
@@ -379,2 +379,5 @@

+           if (StreamDefinitionController.this.streamService != null) {
+               streamDeploymentStates = StreamDefinitionController.this.streamService
+           } else {
+               streamDeploymentStates = null;
+           }
-           streamDeploymentStates = StreamDefinitionController.this.streamService