hibernate/hibernate-orm · error · ArchiveException

Unable to extract bytes from InputStream

Error message

Unable to extract bytes from InputStream

What it means

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.

Source

Thrown at hibernate-core/src/main/java/org/hibernate/boot/archive/internal/ArchiveHelper.java:196

		catch (MalformedURLException e) {
			throw new HibernateException( "Could not access specified jar-file: " + jarFileReference, e );
		}
	}

	/// Extracts the bytes out of an InputStream.  This form is the same as [#getBytesFromInputStream]
	/// except that any [IOException] is wrapped as (runtime) [ArchiveException]
	///
	/// @param inputStream The stream from which to extract bytes.
	///
	/// @return The bytes
	///
	/// @throws ArchiveException Indicates a problem accessing the stream
	public static byte[] getBytesFromInputStreamSafely(InputStream inputStream) throws ArchiveException {
		try {
			return getBytesFromInputStream( inputStream );
		}
		catch (IOException e) {
			throw new ArchiveException( "Unable to extract bytes from InputStream", e );
		}
	}

	/// Extracts the bytes out of an InputStream.
	///
	/// @param inputStream The stream from which to extract bytes.
	///
	/// @return The bytes
	///
	/// @throws IOException Indicates a problem accessing the stream
	///
	/// @see #getBytesFromInputStreamSafely(InputStream)
	public static byte[] getBytesFromInputStream(InputStream inputStream) throws IOException {
		// Optimized by HHH-7835
		int size;
		final List<byte[]> data = new LinkedList<>();
		final int bufferSize = 4096;
		byte[] tmpByte = new byte[bufferSize];

View on GitHub (pinned to fad1729dce)

Solutions

  1. Verify the archive integrity (jar tf my.jar, unzip -t my.jar) and rebuild it if errors are reported.
  2. Deploy atomically — stage the artifact then rename — so Hibernate never reads a half-written jar.
  3. Stop concurrent writes/deletes of scanned archives during startup; retry bootstrap once the deployment has settled.
Defensive patterns

Strategy: retry

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hibernate/hibernate-orm@fad1729dce (2026-08-22). Data as JSON: /api/errors/dc8b2a0a35dd391c. Report an issue: GitHub.