Source:
<code>private static void checkNotAdvertisedWants(UploadPack up, List<ObjectId> notAdvertisedWants, Set<ObjectId> reachableFrom) throws IOException { ObjectReader reader = up.getRevWalk().getObjectReader(); RevWalk walk = new RevWalk(reader); walk.setRetainBody(false); <START> boolean closeWalk = true; <END> try { List<RevObject> wantsAsObjs = objectIdsToRevObjects(walk, notAdvertisedWants); List<RevCommit> wantsAsCommits = wantsAsObjs.stream() .filter(obj -> obj instanceof RevCommit) .map(obj -> (RevCommit) obj) .collect(Collectors.toList()); boolean allWantsAreCommits = wantsAsObjs.size() == wantsAsCommits .size(); boolean repoHasBitmaps = reader.getBitmapIndex() != null; if (!allWantsAreCommits) { if (!repoHasBitmaps) { if (up.transferConfig.isAllowFilter()) { closeWalk = false; ObjectWalk objWalk = walk.toObjectWalkWithSameObjects(); checkReachabilityByWalkingObjects(objWalk, wantsAsObjs, reachableFrom); objWalk.close(); return; } RevObject nonCommit = wantsAsObjs .stream() .filter(obj -> !(obj instanceof RevCommit)) .limit(1) .collect(Collectors.toList()).get(0); throw new WantNotValidException(nonCommit); } checkNotAdvertisedWantsUsingBitmap(reader, reader.getBitmapIndex(), notAdvertisedWants, reachableFrom); return; } ReachabilityChecker reachabilityChecker = walk .createReachabilityChecker(); List<RevCommit> starters = objectIdsToRevCommits(walk, reachableFrom); Optional<RevCommit> unreachable = reachabilityChecker .areAllReachable(wantsAsCommits, starters); if (unreachable.isPresent()) { throw new WantNotValidException(unreachable.get()); } } catch (MissingObjectException notFound) { throw new WantNotValidException(notFound.getObjectId(), notFound); } finally { if (closeWalk) { walk.close(); } } }</code><technical_language>Is this needed? I toObjectWalkWithSameObjects passes closeReader = false, need close walk</technical_language>

Target:
private static void checkNotAdvertisedWants(UploadPack up, List<ObjectId> notAdvertisedWants, Set<ObjectId> reachableFrom) throws IOException { ObjectReader reader = up.getRevWalk().getObjectReader(); RevWalk walk = new RevWalk(reader); walk.setRetainBody(false); try { List<RevObject> wantsAsObjs = objectIdsToRevObjects(walk, notAdvertisedWants); List<RevCommit> wantsAsCommits = wantsAsObjs.stream() .filter(obj -> obj instanceof RevCommit) .map(obj -> (RevCommit) obj) .collect(Collectors.toList()); boolean allWantsAreCommits = wantsAsObjs.size() == wantsAsCommits .size(); boolean repoHasBitmaps = reader.getBitmapIndex() != null; if (!allWantsAreCommits) { if (!repoHasBitmaps) { if (up.transferConfig.isAllowFilter()) { try (ObjectWalk objWalk = walk.toObjectWalkWithSameObjects()) { checkReachabilityByWalkingObjects(objWalk, wantsAsObjs, reachableFrom); } return; } RevObject nonCommit = wantsAsObjs .stream() .filter(obj -> !(obj instanceof RevCommit)) .limit(1) .collect(Collectors.toList()).get(0); throw new WantNotValidException(nonCommit); } checkNotAdvertisedWantsUsingBitmap(reader, reader.getBitmapIndex(), notAdvertisedWants, reachableFrom); return; } ReachabilityChecker reachabilityChecker = walk .createReachabilityChecker(); List<RevCommit> starters = objectIdsToRevCommits(walk, reachableFrom); Optional<RevCommit> unreachable = reachabilityChecker .areAllReachable(wantsAsCommits, starters); if (unreachable.isPresent()) { throw new WantNotValidException(unreachable.get()); } } catch (MissingObjectException notFound) { throw new WantNotValidException(notFound.getObjectId(), notFound); } finally { walk.close(); } }