Compilation Failure in "Calculator Conundrum" Exercis

Description

The “Calculator Conundrum” exercise fails to compile because the IllegalOperationException.java file is redirecting to another file with the same name in a different directory, leading to compilation errors.

> Task :concept:calculator-conundrum:compileJava FAILED  
(source = exercises/concept/calculator-conundrum/.meta/src/reference/java/CalculatorConundrum.java; exercises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java)  
exercises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java:1: error: illegal '.'  
../../../../src/main/java/IllegalOperationException.java  
^  
...  
5 errors  

FAILURE: Build failed with an exception.  
* What went wrong:  
Execution failed for task ':concept:calculator-conundrum:compileJava'.  
> Compilation failed; see the compiler error output for details.  

Problem Details

The issue stems from the IllegalOperationException.java file located at:

exercises/concept/calculator-conundrum/.meta/src/reference/java/IllegalOperationException.java

This file contains a redirection path:

../../../../src/main/java/IllegalOperationException.java

This redirection appears to reference a file outside the exercise’s directory structure, causing the compilation errors.

Suggested Resolution

  • Replace the redirection in the IllegalOperationException.java file with the appropriate exception class definition as it is in the src/main/java/IllegalOperationException.java file.

Outcome

After making the suggested changes, the build was successfully completed, and the compilation errors were resolved.

If anyone has additional suggestions or a different approach to resolving this, please feel free to share! I’d love to hear your thoughts.

Hi @jagdishdrp, compiling the exercise seems to work for me - the exercises/build.gradle file sets the Java source directory to .meta/src/reference/java, so the compileJava task should try to compile the file from .meta/src/reference/java. But I’m also on Linux, so the file is just a symbolic link to the one in src/main/java/IllegalOperationException.java. I’m not quite sure what happens in Windows.

Hello @kahgoh!

In exercises like Binary Search and Tree Building, custom exceptions are defined in both locations, rather than relying on a redirection path as in this exercise. Following the same pattern here would resolve the build failure issue for Windows users while ensuring consistency with the approach used in other exercises.

Just to check are you on Windows? I wasn’t quite sure when I replied earlier if that was the case and I haven’t had the chance to check if I can reproduce it on Windows…

Otherwise, copying the Exception classes like we have in the other exercises sounds good. Another alternative (mentioned in commit message e9e9c2d7) is to see if we can parse the config.json to get the path to the other files, but I’m not quite sure how to do that from Gradle yet.

Yes, this happens in Windows!

I’ll update it, and duplicate it instead of the redirecting path.

1 Like