]> source.dussan.org Git - jgit.git/commit
ReceiveCommand: Explicitly check constructor preconditions 69/100769/6
authorDave Borowitz <dborowitz@google.com>
Wed, 5 Jul 2017 18:07:17 +0000 (14:07 -0400)
committerDave Borowitz <dborowitz@google.com>
Mon, 17 Jul 2017 15:56:35 +0000 (11:56 -0400)
commit21ec281f3e53e72edd77ea3ef142c953ebe0c465
tree1a3d311222e1a83e75a746053bd4d843a87868af
parent00a72e22e6d5a4416b8f2484643d25c94d805c96
ReceiveCommand: Explicitly check constructor preconditions

Some downstream code checks whether a ReceiveCommand is a create or a
delete based on the type field. Other downstream code (in particular a
good chunk of Gerrit code I wrote) checks the same thing by comparing
oldId/newId to zeroId. Unfortunately, there were no strict checks in the
constructor that ensures that zeroId is only set for oldId/newId if the
type argument corresponds, so a caller that passed mismatched IDs and
types would observe completely undefined behavior as a result. This is
and always has been a misuse of the API; throw IllegalArgumentException
so the caller knows that it is a misuse.

Similarly, throw from the constructor if oldId/newId are null. The
non-nullness requirement was already documented. Fix RefDirectoryTest to
not do the wrong thing.

Change-Id: Ie2d0bfed8a2d89e807a41925d548f0f0ce243ecf
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/internal/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/internal/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/ReceiveCommand.java