jpountz commented on code in PR #12897: URL: https://github.com/apache/lucene/pull/12897#discussion_r1431673997
########## lucene/codecs/src/test/org/apache/lucene/codecs/simpletext/TestSimpleTextSegmentInfoFormat.java: ########## @@ -33,4 +43,39 @@ protected Version[] getVersions() { protected Codec getCodec() { return codec; } + + public void testFileIsUTF8() throws IOException { + Directory dir = newDirectory(); + Codec codec = getCodec(); + byte[] id = StringHelper.randomId(); + SegmentInfo info = + new SegmentInfo( + dir, + getVersions()[0], + getVersions()[0], + "_123", + 1, + false, + false, + codec, + Collections.<String, String>emptyMap(), + id, + Collections.emptyMap(), + null); + info.setFiles(Collections.<String>emptySet()); + codec.segmentInfoFormat().write(dir, info, IOContext.DEFAULT); + String segFileName = + IndexFileNames.segmentFileName("_123", "", SimpleTextSegmentInfoFormat.SI_EXTENSION); + try (ChecksumIndexInput input = dir.openChecksumInput(segFileName)) { + long length = input.length(); + if (length > 5_000) { + // Avoid allocating a huge array if the length is wrong + fail("SegmentInfos should not be this large"); + } + byte[] bytes = new byte[(int) length]; + input.readBytes(bytes, 0, bytes.length); + StandardCharsets.UTF_8.newDecoder().decode(ByteBuffer.wrap(bytes)); Review Comment: Maybe use `Term#toString(BytesRef)` which includes such checks already and configures a few more flags on the decoder that look useful? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org