ponder-lab / Optimize-Java-8-Streams-Refactoring

Refactorings for optimizing Java 8 stream client code for greater parallelism and efficiency.
http://cuny.is/streams
Eclipse Public License 1.0
8 stars 7 forks source link

Handle InvalidClassFileException consistently #115

Closed khatchad closed 6 years ago

khatchad commented 6 years ago

@saledouble, after looking at the Util class a bit, I believe that the InvalidClassFileException should be handled similarly to the other methods in the same class. Could you please quickly alter the findEntryPoints() method in the Util class to throw an IllegalArgumentException in a similar fashion as the below method?

https://github.com/ponder-lab/Java-8-Stream-Refactoring/blob/9ad92cac25819eb617749f9b678ace4c3a5dd880/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Util.java#L240-L248

If this exception happens, it is a problem with the argument. Thank you.

yiming-tang-cs commented 6 years ago

In your example, the project catches InvalidClassFileException at first, then throws a IllegalArgumentException. However, in findEntryPoints():

https://github.com/ponder-lab/Java-8-Stream-Refactoring/blob/9ad92cac25819eb617749f9b678ace4c3a5dd880/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Util.java#L426-L450

Line 438 throws an IllegalArgumentException and line 441 throws InvalidClassFileException, i.e., the project cannot catch InvalidClassFileException at first. As such, how can I rewrite code?

khatchad commented 6 years ago

I'll have a look later. Please move on if you are stuck.

khatchad commented 6 years ago

@saledouble Actually, please just do the best you can and propose a fix.

yiming-tang-cs commented 6 years ago

The problem is that in your expectant example, the project catches InvalidClassFileException at first, then throws IllegalArgumentException, but in the method findEntryPoints(), the project throws IllegalArgumentException at first, then throws InvalidClassFileException. It seems that the sequence of throwing makes the change impossible.

khatchad commented 6 years ago

FIrst step is remove the throws clause on the method header: https://github.com/ponder-lab/Java-8-Stream-Refactoring/blob/9ad92cac25819eb617749f9b678ace4c3a5dd880/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Util.java#L426

Then, you need to adjust the method definition to accomidate not throwing the exception in a similar fashion as described in https://github.com/ponder-lab/Java-8-Stream-Refactoring/issues/115#issue-276666264.