Skip to content

Fix IndexOutOfBoundsException in GitUtil.getRepositoryURL when no remotes configured#326

Merged
dividedmind merged 5 commits into
masterfrom
copilot/fix-recording-issue-git-repositories
May 11, 2026
Merged

Fix IndexOutOfBoundsException in GitUtil.getRepositoryURL when no remotes configured#326
dividedmind merged 5 commits into
masterfrom
copilot/fix-recording-issue-git-repositories

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Recording fails with IndexOutOfBoundsException in GitUtil.getRepositoryURL when the git repository has no remotes — the fallback path of remotes.get(0) is hit unconditionally on a potentially empty list.

Changes

  • Guard against empty remotes list — return null early if remotes.isEmpty() instead of falling through to remotes.get(0)
  • Guard against empty URIs list — return null if the selected remote has no URIs configured
  • Use orElseGet over orElse — avoids eagerly evaluating remotes.get(0) when "origin" is present
  • getRepositoryURL() returns null instead of "" when no URL is available, allowing callers to distinguish "no remote" from an actual empty string
  • AppMapSerializer.writeMetadata() only writes the repository key when getRepositoryURL() returns a non-null value
// Before
List<URIish> uris = originConfig.isPresent() ? originConfig.get().getURIs() : remotes.get(0).getURIs();
return uris.get(0).toASCIIString(); // throws if remotes or uris is empty

// After
if (remotes.isEmpty()) return null;
RemoteConfig remote = originConfig.orElseGet(() -> remotes.get(0));
List<URIish> uris = remote.getURIs();
if (uris.isEmpty()) return null;
return uris.get(0).toASCIIString();

Copilot AI linked an issue May 5, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix recording failure in git repositories without remotes Fix IndexOutOfBoundsException in GitUtil.getRepositoryURL when no remotes configured May 5, 2026
Copilot finished work on behalf of kgilpin May 5, 2026 18:51
Copilot AI requested a review from kgilpin May 5, 2026 18:51
Copy link
Copy Markdown
Contributor

@kgilpin kgilpin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getRepositoryURL should be modified to return String | null, or to return String[] which might be empty, and caller sites updated accordingly. @copilot

…itory key in serializer

Agent-Logs-Url: https://github.com/getappmap/appmap-java/sessions/9269e403-28ed-4394-be5f-17ca657e822a

Co-authored-by: kgilpin <86395+kgilpin@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 5, 2026

getRepositoryURL should be modified to return String | null, or to return String[] which might be empty, and caller sites updated accordingly. @copilot

Done in 5956839. getRepositoryURL() now returns null (instead of "") when no remotes are configured, a remote has no URIs, or an exception occurs. The caller in AppMapSerializer.writeMetadata() now only writes the repository key when the returned value is non-null.

Copilot finished work on behalf of kgilpin May 5, 2026 19:02
Copilot AI requested a review from kgilpin May 5, 2026 19:02
@kgilpin kgilpin requested a review from dividedmind May 6, 2026 01:27
@kgilpin kgilpin marked this pull request as ready for review May 6, 2026 01:27
@dividedmind dividedmind force-pushed the copilot/fix-recording-issue-git-repositories branch from 8a69319 to 871a9c9 Compare May 11, 2026 11:41
Copy link
Copy Markdown
Contributor

@dividedmind dividedmind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added tests and changed the agent to look for the git repo based on the appmap.yml instead of the working directory (which is IMO less surprising and allowed me to add unit tests without ungodly complications — it seems JVM doesn't have a concept of the working directory or how to change it).

@kgilpin please take a look; if it looks good, you can go ahead and squash merge (there's a bunch of wip commits here); please make sure to use proper fix: ... commit message subject for semantic-release. Or just let me know and I'll do it :)

Copy link
Copy Markdown
Contributor

@kgilpin kgilpin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - I have been using this in my benchmark

@dividedmind dividedmind merged commit 48723a8 into master May 11, 2026
7 of 12 checks passed
@dividedmind dividedmind deleted the copilot/fix-recording-issue-git-repositories branch May 11, 2026 15:41
@appland-release
Copy link
Copy Markdown

🎉 This PR is included in version 1.30.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Recording fails in git repositories without remotes

4 participants