Skip to content

Fix #82 - #85

Merged
StRigaud merged 3 commits into
mainfrom
fix-#82
Aug 6, 2026
Merged

StRigaud merged 3 commits into
mainfrom
fix-#82

Conversation

@StRigaud

@StRigaud StRigaud commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes #82

Root cause — In FijiApposeTaskListener.errorListener() (src/main/java/fiji/plugin/appose/cellpose/FijiApposeTaskListener.java:114), the env-name was extracted with two independent whole-string searches:

str.substring( str.indexOf( "The" ) + 3, str.indexOf( "environment" ) )

On the first run the str passed by Appose's error stream is a large accumulated buffer (length 39273 in your trace), not a single line. In that buffer:
indexOf("The") matches the "The" in the final The … environment has been installed. line → begin = 39232
indexOf("environment") matches the first "environment" that appeared much earlier in the log → end = 586
So substring(39232, 586) has begin > end → StringIndexOutOfBoundsException. It's non-blocking (thrown on a background stream-reader thread, cellpose keeps running) and doesn't recur because subsequent runs emit a short buffer where the two indexOf calls happen to align.

Fix — Anchor on the real phrase and search backwards from it, with bounds guards:

final int envIdx = str.indexOf( "environment has been installed." );
final int theIdx = str.lastIndexOf( "The", envIdx );
final String envName = ( theIdx >= 0 && theIdx + 3 <= envIdx )
        ? str.substring( theIdx + 3, envIdx ).trim()
        : "";
IJ.showStatus( "Python environment " + envName + " is ready." );

lastIndexOf("The", envIdx) finds the "The" belonging to the same line as the installed-phrase, so begin never exceeds end regardless of buffer size, and the guard falls back to an empty name if the pattern isn't found. Uses of .trim() to fixed the missing space before "is ready." for a cleaner status message.

Still to be tested to be sure all is good before merge!

@StRigaud
StRigaud merged commit 3527b57 into main Aug 6, 2026
1 check passed
@StRigaud
StRigaud deleted the fix-#82 branch August 6, 2026 11:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StringIndexOutOfBoundsException

1 participant