Skip to content

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

Open
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-recording-issue-git-repositories
Open

Fix IndexOutOfBoundsException in GitUtil.getRepositoryURL when no remotes configured#326
Copilot wants to merge 3 commits intomasterfrom
copilot/fix-recording-issue-git-repositories

Conversation

Copy link
Copy Markdown

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
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
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.

Recording fails in git repositories without remotes

2 participants