{"record":{"id":"dc8b2a0a35dd391c","repo":"hibernate/hibernate-orm","slug":"unable-to-extract-bytes-from-inputstream","errorCode":null,"errorMessage":"Unable to extract bytes from InputStream","messagePattern":"Unable to extract bytes from InputStream","errorType":"exception","errorClass":"ArchiveException","httpStatus":null,"severity":"error","filePath":"hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ArchiveHelper.java","lineNumber":196,"sourceCode":"\t\tcatch (MalformedURLException e) {\n\t\t\tthrow new HibernateException( \"Could not access specified jar-file: \" + jarFileReference, e );\n\t\t}\n\t}\n\n\t/// Extracts the bytes out of an InputStream.  This form is the same as [#getBytesFromInputStream]\n\t/// except that any [IOException] is wrapped as (runtime) [ArchiveException]\n\t///\n\t/// @param inputStream The stream from which to extract bytes.\n\t///\n\t/// @return The bytes\n\t///\n\t/// @throws ArchiveException Indicates a problem accessing the stream\n\tpublic static byte[] getBytesFromInputStreamSafely(InputStream inputStream) throws ArchiveException {\n\t\ttry {\n\t\t\treturn getBytesFromInputStream( inputStream );\n\t\t}\n\t\tcatch (IOException e) {\n\t\t\tthrow new ArchiveException( \"Unable to extract bytes from InputStream\", e );\n\t\t}\n\t}\n\n\t/// Extracts the bytes out of an InputStream.\n\t///\n\t/// @param inputStream The stream from which to extract bytes.\n\t///\n\t/// @return The bytes\n\t///\n\t/// @throws IOException Indicates a problem accessing the stream\n\t///\n\t/// @see #getBytesFromInputStreamSafely(InputStream)\n\tpublic static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException {\n\t\t// Optimized by HHH-7835\n\t\tint size;\n\t\tfinal List<byte[]> data = new LinkedList<>();\n\t\tfinal int bufferSize = 4096;\n\t\tbyte[] tmpByte = new byte[bufferSize];","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/hibernate/hibernate-orm/blob/fad1729dce015f908198d57a8d80274a30f905a5/hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ArchiveHelper.java#L178-L214","documentation":"ArchiveHelper.getBytesFromInputStreamSafely slurps an archive entry into a byte array (so the stream can be closed immediately) and wraps any IOException as ArchiveException 'Unable to extract bytes from InputStream'. The root cause is always an I/O failure reading the entry stream — truncated or corrupted archive, stream closed underneath, or a file lock/permission problem.","triggerScenarios":"Hibernate reads the bytes of a scanned archive entry (class file, orm.xml, package-info) and the underlying stream throws IOException: corrupted zip structure, truncated entry, file deleted or locked mid-scan.","commonSituations":"Hot redeploys deleting/replacing jars while they are scanned; artifacts corrupted by interrupted builds or partial container-image copies; antivirus or other processes locking files on Windows.","solutions":["Verify the archive integrity (jar tf my.jar, unzip -t my.jar) and rebuild it if errors are reported.","Deploy atomically — stage the artifact then rename — so Hibernate never reads a half-written jar.","Stop concurrent writes/deletes of scanned archives during startup; retry bootstrap once the deployment has settled."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"Catch org.hibernate.boot.archive.spi.ArchiveException around bootstrap. Inspect the entry being read, verify the jar with jar tf/ unzip -t, and if the archive was being written during a redeploy, retry bootstrap once after the deployment settles; otherwise replace the corrupted jar.","preventionTips":["Verify archive integrity in the build pipeline before shipping.","Deploy atomically (stage then rename) so scanners never see partial jars.","Prevent concurrent writes/deletes of scanned archives during startup."],"tags":["hibernate","archive-scanning","io","corrupted-jar","deployment"],"backgroundTag":"archive-read-io-error","analyzedSha":"fad1729dce015f908198d57a8d80274a30f905a5","analyzedAt":"2026-08-22T04:13:57.527Z","schemaVersion":2},"datasetVersion":"2026-08-22T09:17:25.309Z"}