Package org.eclipse.jgit.lib

## Class ObjectChecker

- java.lang.Object
- - org.eclipse.jgit.lib.ObjectChecker

    public class ObjectChecker
    extends Object

Verifies that an object is formatted correctly.

Verifications made by this class only check that the fields of an object are formatted correctly. The ObjectId checksum of the object is not verified, and connectivity links between objects are also not verified. Its assumed that the caller can provide both of these validations on its own.

Instances of this class are not thread safe, but they may be reused to perform multiple object validations.

### Field Summary

Fields
`static byte[]` `author` Header "author "
`static byte[]` `committer` Header "committer "
`static byte[]` `encoding` Header "encoding "
`static byte[]` `object` Header "object "
`static byte[]` `parent` Header "parent "
`static byte[]` `tag` Header "tag "
`static byte[]` `tagger` Header "tagger "
`static byte[]` `tree` Header "tree "
`static byte[]` `type` Header "type "

### Constructor Summary

Constructors
`ObjectChecker()`

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `check​(int objType, byte[] raw)` Check an object for parsing errors.
`void` `checkBlob​(byte[] raw)` Check a blob for errors.
`void` `checkCommit​(byte[] raw)` Check a commit for errors.
`void` `checkPath​(byte[] raw, int ptr, int end)` Check tree path entry for validity.
`void` `checkPath​(String path)` Check tree path entry for validity.
`void` `checkPathSegment​(byte[] raw, int ptr, int end)` Check tree path entry for validity.
`void` `checkTag​(byte[] raw)` Check an annotated tag for errors.
`void` `checkTree​(byte[] raw)` Check a canonical formatted tree for errors.
`ObjectChecker` `setAllowLeadingZeroFileMode​(boolean allow)` Enable accepting leading zero mode in tree entries.
`ObjectChecker` `setSafeForMacOS​(boolean mac)` Restrict trees to only names legal on Mac OS X platforms.
`ObjectChecker` `setSafeForWindows​(boolean win)` Restrict trees to only names legal on Windows platforms.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### tree

    public static final byte[] tree

Header "tree "

#### parent

    public static final byte[] parent

Header "parent "

#### author

    public static final byte[] author

Header "author "

#### committer

    public static final byte[] committer

Header "committer "

#### encoding

    public static final byte[] encoding

Header "encoding "

#### object

    public static final byte[] object

Header "object "

#### type

    public static final byte[] type

Header "type "

#### tag

    public static final byte[] tag

Header "tag "

#### tagger

    public static final byte[] tagger

Header "tagger "

### Constructor Detail

#### ObjectChecker

    public ObjectChecker()

### Method Detail

#### setAllowLeadingZeroFileMode

    public ObjectChecker setAllowLeadingZeroFileMode​(boolean allow)

Enable accepting leading zero mode in tree entries.

Some broken Git libraries generated leading zeros in the mode part of tree entries. This is technically incorrect but gracefully allowed by git-core. JGit rejects such trees by default, but may need to accept them on broken histories.

Parameters:
  `allow` - allow leading zero mode.
Returns:
  `this`.
Since:
  3.4

#### setSafeForWindows

    public ObjectChecker setSafeForWindows​(boolean win)

Restrict trees to only names legal on Windows platforms.

Also rejects any mixed case forms of reserved names (`.git`).

Parameters:
  `win` - true if Windows name checking should be performed.
Returns:
  `this`.
Since:
  3.4

#### setSafeForMacOS

    public ObjectChecker setSafeForMacOS​(boolean mac)

Restrict trees to only names legal on Mac OS X platforms.

Rejects any mixed case forms of reserved names (`.git`) for users working on HFS+ in case-insensitive (default) mode.

Parameters:
  `mac` - true if Mac OS X name checking should be performed.
Returns:
  `this`.
Since:
  3.4

#### check

    public void check​(int objType,
                      byte[] raw)
               throws CorruptObjectException

Check an object for parsing errors.

Parameters:
  `objType` - type of the object. Must be a valid object type code in `Constants`.
  `raw` - the raw data which comprises the object. This should be in the canonical format (that is the format used to generate the ObjectId of the object). The array is never modified.
Throws:
  `CorruptObjectException` - if an error is identified.

#### checkCommit

    public void checkCommit​(byte[] raw)
                     throws CorruptObjectException

Check a commit for errors.

Parameters:
  `raw` - the commit data. The array is never modified.
Throws:
  `CorruptObjectException` - if any error was detected.

#### checkTag

    public void checkTag​(byte[] raw)
                  throws CorruptObjectException

Check an annotated tag for errors.

Parameters:
  `raw` - the tag data. The array is never modified.
Throws:
  `CorruptObjectException` - if any error was detected.

#### checkTree

    public void checkTree​(byte[] raw)
                   throws CorruptObjectException

Check a canonical formatted tree for errors.

Parameters:
  `raw` - the raw tree data. The array is never modified.
Throws:
  `CorruptObjectException` - if any error was detected.

#### checkPath

    public void checkPath​(String path)
                   throws CorruptObjectException

Check tree path entry for validity.

Unlike `checkPathSegment(byte[], int, int)`, this version scans a multi-directory path string such as `"src/main.c"`.

Parameters:
  `path` - path string to scan.
Throws:
  `CorruptObjectException` - path is invalid.
Since:
  3.6

#### checkPath

    public void checkPath​(byte[] raw,
                          int ptr,
                          int end)
                   throws CorruptObjectException

Check tree path entry for validity.

Unlike `checkPathSegment(byte[], int, int)`, this version scans a multi-directory path string such as `"src/main.c"`.

Parameters:
  `raw` - buffer to scan.
  `ptr` - offset to first byte of the name.
  `end` - offset to one past last byte of name.
Throws:
  `CorruptObjectException` - path is invalid.
Since:
  3.6

#### checkPathSegment

    public void checkPathSegment​(byte[] raw,
                                 int ptr,
                                 int end)
                          throws CorruptObjectException

Check tree path entry for validity.

Parameters:
  `raw` - buffer to scan.
  `ptr` - offset to first byte of the name.
  `end` - offset to one past last byte of name.
Throws:
  `CorruptObjectException` - name is invalid.
Since:
  3.4

#### checkBlob

    public void checkBlob​(byte[] raw)
                   throws CorruptObjectException

Check a blob for errors.

Parameters:
  `raw` - the blob data. The array is never modified.
Throws:
  `CorruptObjectException` - if any error was detected.