[EGIT PATCH 11/31] Clean up exception issues in RemoteRefUpdate

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



IllegalArgumentException was probably a wrong choice for exception
thrown in RemoteRefUpdate when src object can't be resolved - it should
be checked one.

Now it's IOException, which makes call more safe for external clients.

Signed-off-by: Marek Zawirski <marek.zawirski@xxxxxxxxx>
---
 .../spearce/jgit/transport/RemoteRefUpdate.java    |   12 +++---
 .../src/org/spearce/jgit/transport/Transport.java  |   48 +++++++++----------
 2 files changed, 29 insertions(+), 31 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java
index 7db6c55..5afb8a4 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/RemoteRefUpdate.java
@@ -166,23 +166,23 @@ public class RemoteRefUpdate {
 	 *            remote ref with this name.
 	 * @throws IOException
 	 *             when I/O error occurred during creating
-	 *             {@link TrackingRefUpdate} for local tracking branch.
+	 *             {@link TrackingRefUpdate} for local tracking branch or srcRef
+	 *             can't be resolved to any object.
 	 * @throws IllegalArgumentException
-	 *             if some required parameter was null or srcRef can't be
-	 *             resolved to any object.
+	 *             if some required parameter was null
 	 */
 	public RemoteRefUpdate(final Repository db, final String srcRef,
 			final String remoteName, final boolean forceUpdate,
 			final String localName, final ObjectId expectedOldObjectId)
 			throws IOException {
 		if (remoteName == null)
-			throw new IllegalArgumentException("remote name can't be null");
+			throw new IllegalArgumentException("Remote name can't be null.");
 		this.srcRef = srcRef;
 		this.newObjectId = (srcRef == null ? ObjectId.zeroId() : db
 				.resolve(srcRef));
 		if (newObjectId == null)
-			throw new IllegalArgumentException(
-					"source ref doesn't resolve to any object");
+			throw new IOException("Source ref " + srcRef
+					+ " doesn't resolve to any object.");
 		this.remoteName = remoteName;
 		this.forceUpdate = forceUpdate;
 		if (localName != null && db != null)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
index 8e42516..939347e 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
@@ -39,6 +39,7 @@
 
 package org.spearce.jgit.transport;
 
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -211,7 +212,7 @@ public abstract class Transport {
 
 		throw new NotSupportedException("URI not supported: " + remote);
 	}
-	
+
 	/**
 	 * Convert push remote refs update specification from {@link RefSpec} form
 	 * to {@link RemoteRefUpdate}. Conversion expands wildcards by matching
@@ -228,38 +229,29 @@ public abstract class Transport {
 	 *            fetch specifications used for finding localtracking refs. May
 	 *            be null or empty collection.
 	 * @return collection of set up {@link RemoteRefUpdate}.
-	 * @throws TransportException
+	 * @throws IOException
 	 *             when problem occurred during conversion or specification set
 	 *             up: most probably, missing objects or refs.
 	 */
 	public static Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
 			final Repository db, final Collection<RefSpec> specs,
-			Collection<RefSpec> fetchSpecs) throws TransportException {
+			Collection<RefSpec> fetchSpecs) throws IOException {
 		if (fetchSpecs == null)
 			fetchSpecs = Collections.emptyList();
 		final List<RemoteRefUpdate> result = new LinkedList<RemoteRefUpdate>();
 		final Collection<RefSpec> procRefs = expandPushWildcardsFor(db, specs);
 
 		for (final RefSpec spec : procRefs) {
-			try {
-				final String srcRef = spec.getSource();
-				// null destination (no-colon in ref-spec) is a special case
-				final String remoteName = (spec.getDestination() == null ? spec
-						.getSource() : spec.getDestination());
-				final boolean forceUpdate = spec.isForceUpdate();
-				final String localName = findTrackingRefName(remoteName,
-						fetchSpecs);
-
-				final RemoteRefUpdate rru = new RemoteRefUpdate(db, srcRef,
-						remoteName, forceUpdate, localName, null);
-				result.add(rru);
-			} catch (TransportException x) {
-				throw x;
-			} catch (Exception x) {
-				throw new TransportException(
-						"Problem with resolving push ref spec \"" + spec
-								+ "\" locally: " + x.getMessage(), x);
-			}
+			final String srcRef = spec.getSource();
+			// null destination (no-colon in ref-spec) is a special case
+			final String remoteName = (spec.getDestination() == null ? spec
+					.getSource() : spec.getDestination());
+			final boolean forceUpdate = spec.isForceUpdate();
+			final String localName = findTrackingRefName(remoteName, fetchSpecs);
+
+			final RemoteRefUpdate rru = new RemoteRefUpdate(db, srcRef,
+					remoteName, forceUpdate, localName, null);
+			result.add(rru);
 		}
 		return result;
 	}
@@ -643,7 +635,13 @@ public abstract class Transport {
 			TransportException {
 		if (toPush == null || toPush.isEmpty()) {
 			// If the caller did not ask for anything use the defaults.
-			toPush = findRemoteRefUpdatesFor(push);
+			try {
+				toPush = findRemoteRefUpdatesFor(push);
+			} catch (final IOException e) {
+				throw new TransportException(
+						"Problem with resolving push ref specs locally: "
+								+ e.getMessage(), e);
+			}
 			if (toPush.isEmpty())
 				throw new TransportException("Nothing to push.");
 		}
@@ -665,12 +663,12 @@ public abstract class Transport {
 	 * @param specs
 	 *            collection of RefSpec to convert.
 	 * @return collection of set up {@link RemoteRefUpdate}.
-	 * @throws TransportException
+	 * @throws IOException
 	 *             when problem occurred during conversion or specification set
 	 *             up: most probably, missing objects or refs.
 	 */
 	public Collection<RemoteRefUpdate> findRemoteRefUpdatesFor(
-			final Collection<RefSpec> specs) throws TransportException {
+			final Collection<RefSpec> specs) throws IOException {
 		return findRemoteRefUpdatesFor(local, specs, fetch);
 	}
 
-- 
1.5.6.3

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux