Stuck on MG5: Locate executable files

Hello Folks,

I know this exact problem has been asked before, however I am running into an interesting issue. When I run the code locally, it seems to work. However when I submit the code the exact same test case fails. Attaching output from my terminal for reference.

Language: Java, version 25

Happy to share the code, if required.

Thanks in advance!!!

░▒▓    ~/C/Github/codecrafters-shell-java  on   master  codecrafters test                                                                                    INT ✘  took 25s   25   at 07:46:14 PM  ▓▒░
Initiating test run...

⚡ This is a turbo test run. https://codecrafters.io/turbo

Running tests on your code. Logs should appear shortly...

[compile] WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
[compile] WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/usr/share/maven/lib/guice-5.1.0-classes.jar)
[compile] WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
[compile] WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release
[compile] Moved ./.codecrafters/run.sh → ./your_program.sh
[compile] Compilation successful.

Debug = true

[tester::#MG5] Running tests for Stage #MG5 (Locate executable files)
[tester::#MG5] [setup] export PATH=/tmp/fox:$PATH
[tester::#MG5] [setup] export PATH=/tmp/bee:$PATH
[tester::#MG5] [setup] export PATH=/tmp/pig:$PATH
[tester::#MG5] [setup] PATH is now: /tmp/pig:/tmp/bee:/tmp/fox:...
[tester::#MG5] [setup] Files created:
[tester::#MG5] [setup] - /tmp/fox/my_exe (not executable)
[tester::#MG5] [setup] - /tmp/pig/my_exe (not executable)
[tester::#MG5] [setup] - /tmp/bee/my_exe (executable)
[tester::#MG5] Running ./your_program.sh
[your-program] $ type cat
[your-program] cat: not found
[tester::#MG5] ^ Line does not match expected value.
[tester::#MG5] Expected: "cat is /bin/cat"
[tester::#MG5] Received: "cat: not found"
[your-program] $
[tester::#MG5] Assertion failed.
[tester::#MG5] Test failed

View our article on debugging test failures: https://codecrafters.io/debug


░▒▓    ~/C/Github/codecrafters-shell-java  on   master  ./your_program.sh                                                                                        ✔  took 16s   25   at 07:54:02 PM  ▓▒░
WARNING: A restricted method in java.lang.System has been called
WARNING: java.lang.System::load has been called by org.fusesource.jansi.internal.JansiLoader in an unnamed module (file:/opt/homebrew/Cellar/maven/3.9.9/libexec/lib/jansi-2.4.1.jar)
WARNING: Use --enable-native-access=ALL-UNNAMED to avoid a warning for callers in this module
WARNING: Restricted methods will be blocked in a future release unless native access is enabled

WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper (file:/opt/homebrew/Cellar/maven/3.9.9/libexec/lib/guava-33.2.1-jre.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.common.util.concurrent.AbstractFuture$UnsafeAtomicHelper
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
$ type cat
cat is /bin/cat
$

Hey @vineeth-au, could you push a version of your code that’s working locally? I can take a closer look and debug this with you.

Hey @andy1li ,
Thank you for the quick reply. Here is the repo with my code working locally…

1 Like

@vineeth-au Mind clarifying a bit why the list is filtered by not executable? :thinking:

Absolutely… I originally had it as .filter(Files::isExecutable, but when I ran the test case type cat it did not seem to work. I am guessing some sort of Permission issue, need to read the docs and understand more.

To test it out I reversed it and gave it a shot. Not sure why it’s working… Need to dig a bit more…

PS: My original commit

@andy1li Once again, thank you so much for going through the code. It’s quite messy and have not refactored it yet…

1 Like

@vineeth-au Let me know if you’d like help digging deeper beyond the not-executable filter.

Thank you, I will figure out the executable… But I am interested to know why there is a difference in output for local vs when I submit the code… Even when I have the filter, the tests seem to fail; that is what I am actually stuck on…

PS: If I am really not able to figure out the executable filter, I will let you know what I find. :slight_smile:

@andy1li sorry for spamming. Figured out the issue with executable filter. The issue was .map(Path::getFileName) returned only the file name and not the entire path. Pushed the .filter(Files::isExecutable)a level up and started working… mystery solved…

However the mystery of why the test case is not passing when I submit the code still remains… The code seems to work fine locally.

Fixed the issue. It was incorrect logic in getSystemEnvironmentPaths
:person_facepalming: Sorry for raising an issue prematurely. Should have checked properly. Thanks for helping out @andy1li

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.