Merge branch 'stable-5.12'

* stable-5.12:
  LockFile: create OutputStream only when needed
  Remove ReftableNumbersNotIncreasingException

Change-Id: I9d85187d00771beef908f1136015d059024f4118
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableStack.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableStack.java
index b5e3927..f02c861 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableStack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileReftableStack.java
@@ -131,33 +131,6 @@
 		return stats;
 	}
 
-	/** Thrown if the update indices in the stack are not monotonic */
-	public static class ReftableNumbersNotIncreasingException
-			extends RuntimeException {
-		private static final long serialVersionUID = 1L;
-
-		String name;
-
-		long lastMax;
-
-		long min;
-
-		ReftableNumbersNotIncreasingException(String name, long lastMax,
-				long min) {
-			this.name = name;
-			this.lastMax = lastMax;
-			this.min = min;
-		}
-
-		@SuppressWarnings({ "nls", "boxing" })
-		@Override
-		public String toString() {
-			return String.format(
-					"ReftableNumbersNotIncreasingException %s: min %d, lastMax %d",
-					name, min, lastMax);
-		}
-	}
-
 	/**
 	 * Reloads the stack, potentially reusing opened reftableReaders.
 	 *
@@ -176,7 +149,6 @@
 		List<ReftableReader> newTables = new ArrayList<>();
 		List<StackEntry> newStack = new ArrayList<>(stack.size() + 1);
 		try {
-			ReftableReader last = null;
 			for (String name : names) {
 				StackEntry entry = new StackEntry();
 				entry.name = name;
@@ -194,15 +166,6 @@
 					newTables.add(t);
 				}
 
-				if (last != null) {
-					// TODO: move this to MergedReftable
-					if (last.maxUpdateIndex() >= t.minUpdateIndex()) {
-						throw new ReftableNumbersNotIncreasingException(name,
-								last.maxUpdateIndex(), t.minUpdateIndex());
-					}
-				}
-				last = t;
-
 				entry.reftableReader = t;
 				newStack.add(entry);
 			}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
index ab407a6..f57581a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/LockFile.java
@@ -218,14 +218,14 @@
 					int r;
 					while ((r = fis.read(buf)) >= 0) {
 						out.write(buf, 0, r);
-					}
 				}
-			} catch (FileNotFoundException fnfe) {
-				if (ref.exists()) {
-					throw fnfe;
-				}
-				// Don't worry about a file that doesn't exist yet, it
-				// conceptually has no current content to copy.
+			}
+		} catch (FileNotFoundException fnfe) {
+			if (ref.exists()) {
+				throw fnfe;
+			}
+			// Don't worry about a file that doesn't exist yet, it
+			// conceptually has no current content to copy.
 			}
 		} catch (IOException | RuntimeException | Error ioe) {
 			unlock();
@@ -322,9 +322,9 @@
 				if (out == null) {
 					os = getStream();
 					if (fsync) {
-						out = Channels.newOutputStream(os.getChannel());
+			out = Channels.newOutputStream(os.getChannel());
 					} else {
-						out = os;
+			out = os;
 					}
 				}
 				return out;
@@ -359,10 +359,10 @@
 					}
 					if (out != null) {
 						if (fsync) {
-							os.getChannel().force(true);
+						os.getChannel().force(true);
 						}
-						out.close();
-						os = null;
+					out.close();
+					os = null;
 					}
 					written = true;
 				} catch (IOException | RuntimeException | Error ioe) {