tsantalis / JDeodorant

JDeodorant
https://marketplace.eclipse.org/content/jdeodorant
MIT License
139 stars 59 forks source link

Extracted method after refactoring Long Method throws an exception not thrown in the original code. #71

Closed rsain closed 5 years ago

rsain commented 5 years ago

Project: Perseo-core (https://github.com/telefonicaid/perseo-core) Commit: 19189b66cbb0ba97edad41147f749e3bb2d7d2fb Package: src.test.java.com.telefonica.iot.perseo Classname: TimeRulesStoreTest Method: public void testCleanAllRules() Operating system: Linux Debian Eclipse version: 2019-03 (4.11.0) JDeodorant plug-in version: 5.0.70

When I perform Long Method refactoring from the JDeodorant Eclipse plug-in on the TimeRulesStoreTest method, a new exception (JSONException in this case) is thrown from the extracted method. This exception was not thrown in the original code and, therefore, the JSONException was not previously imported in the current class. This ends up with compilation errors in the project.

image

image

tsantalis commented 5 years ago

I am getting some compilation errors after building the project with mvn eclipse:eclipse related to

import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;

in class /perseo-core/src/test/java/com/telefonica/iot/perseo/UtilsTest.java @rsain What version of java you used to build the project?

rsain commented 5 years ago

I am using JavaSE-1.8 (java-8-oracle).

I hope it helps.

tsantalis commented 5 years ago

I excluded /perseo-core/src/test/java/com/telefonica/iot/perseo/UtilsTest.java from sources to replicate the bug. All put calls throw JSONException body.put("name", ruleName); So, I think it's correct to add throws in the signature of the extracted method. The code should be updated to automatically add the missing import declaration statement.