Hi, 

Does anyone come across this error in `picard SortSam` command? ([site](https://broadinstitute.github.io/picard/index.html#GettingHelp))

The command run: 

    java -Djava.io.tmpdir=$TMP_SPACE -jar $PICARD \
       SortSam I=$IN_BAM O=$OUT_BAM SORT_ORDER=coordinate \
       VALIDATION_STRINGENCY=LENIENT 

The command tries to sort a bam file by coordinate. It runs for 2 hours and then it shows the error below:

> [Thu Jan 07 00:14:51 UTC 2021] picard.sam.SortSam done. Elapsed time: 150.85 minutes.
Runtime.totalMemory()=24461180928
To get help, see http://broadinstitute.github.io/picard/index.html#GettingHelp
Exception in thread "main" java.lang.IllegalArgumentException: Value (4135) to large to be written as ubyte.
        at htsjdk.samtools.util.BinaryCodec.writeUByte(BinaryCodec.java:331)
        at htsjdk.samtools.BAMRecordCodec.encode(BAMRecordCodec.java:155)
        at htsjdk.samtools.BAMRecordCodec.encode(BAMRecordCodec.java:40)
        at htsjdk.samtools.util.SortingCollection.spillToDisk(SortingCollection.java:254)
        at htsjdk.samtools.util.SortingCollection.add(SortingCollection.java:182)
        at htsjdk.samtools.SAMFileWriterImpl.addAlignment(SAMFileWriterImpl.java:187)
        at picard.sam.SortSam.doWork(SortSam.java:161)
        at picard.cmdline.CommandLineProgram.instanceMain(CommandLineProgram.java:304)
        at picard.cmdline.PicardCommandLine.instanceMain(PicardCommandLine.java:103)
        at picard.cmdline.PicardCommandLine.main(PicardCommandLine.java:113)

I search a bit, but I'm not a java programmer. As far as I can tell, it does not seem to be a problem of space neither RAM memory (I run this command in one server with big memory). The file in question is quite big (a few hundred GB). 

The error seems related with a problem to write into the disk, but I'm not familiar with what is `ubyte` neither how to interpret and possibly solve the problem (if possible).

Thank you in advance for help or advice, 

António

> htsjdk.samtools.BAMRecordCodec.encode(BAMRecordCodec.java:155) at 

the error is here:  https://github.com/samtools/htsjdk/blob/master/src/main/java/htsjdk/samtools/BAMRecordCodec.java#L155

it's thrown when the read NAME is too long (the SAM spec says length(name) < 256  (coded as uint8_t) )

so it's a problem with your bam. Check the length of your read names.