diff src/org/tmatesoft/hg/core/Nodeid.java @ 535:d9c07e1432c4

Issue 42: tolerate lines in .hgtags that do not conform to its format specification
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Tue, 05 Feb 2013 15:54:37 +0100
parents 465316bf97e8
children d29d9dc6c128
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/core/Nodeid.java	Mon Feb 04 18:00:55 2013 +0100
+++ b/src/org/tmatesoft/hg/core/Nodeid.java	Tue Feb 05 15:54:37 2013 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2010-2011 TMate Software Ltd
+ * Copyright (c) 2010-2013 TMate Software Ltd
  *  
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -166,7 +166,7 @@
 	 * @return object representation
 	 * @throws HgBadNodeidFormatException custom {@link IllegalArgumentException} subclass when argument doesn't match encoded form of 20-bytes sha1 digest. 
 	 */
-	public static Nodeid fromAscii(String asciiRepresentation) {
+	public static Nodeid fromAscii(String asciiRepresentation) throws HgBadNodeidFormatException {
 		if (asciiRepresentation.length() != 40) {
 			throw new HgBadNodeidFormatException(String.format("Bad value: %s", asciiRepresentation));
 		}
@@ -178,9 +178,9 @@
 	 * Parse encoded representation. Similar to {@link #fromAscii(String)}.
 	 * @throws HgBadNodeidFormatException custom {@link IllegalArgumentException} subclass when bytes are not hex digits or number of bytes != 40 (160 bits) 
 	 */
-	public static Nodeid fromAscii(byte[] asciiRepresentation, int offset, int length) {
+	public static Nodeid fromAscii(byte[] asciiRepresentation, int offset, int length) throws HgBadNodeidFormatException {
 		if (length != 40) {
-			throw new IllegalArgumentException();
+			throw new HgBadNodeidFormatException(String.format("Expected 40 hex characters for nodeid, not %d", length));
 		}
 		try {
 			byte[] data = new byte[20];
@@ -189,6 +189,8 @@
 				return NULL;
 			}
 			return new Nodeid(data, false);
+		} catch (HgBadNodeidFormatException ex) {
+			throw ex;
 		} catch (IllegalArgumentException ex) {
 			throw new HgBadNodeidFormatException(ex.getMessage());
 		}