Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] ObjectInserter#idFor() question

Hi JGit devs, 
I stumbled upon what I would call an inconsistency in how idFor() behaves, but maybe this by design. The idFor( objectType, lenth, inputStream ) method checks if the given length and the actual length of the inputStream match and throws an IOException if not. But only if the given length is greater than the actual length. If the inputSteam has less bytes than specified by the length argument the method succeeds. 
Here is some code to illustrate: 
  InputStream twoByteStream = new ByteArrayInputStream( new byte[] { 1, 2 } ) ; 
  Formatter idCalculator = new Formatter(); 
  // Succeeds, i.e. silently ignores the difference between given and actual length 
  idCalculator.idFor( Constants.OBJ_BLOB, 1, twoByteStream ); 
  // Fails with an IOException 
  idCalculator.idFor( Constants.OBJ_BLOB, 3, twoByteStream ); 
IMO the method should behave consistently and either always or never throw an exception if there is a mismatch between the specified and the actual length. 
Any thoughts? 

Back to the top