JDK-6539564 : com.sun.jnlp.PersistenceServiceImpl fires a ArrayIndexOutOfBoundsException
  • Type: Bug
  • Component: deploy
  • Sub-Component: webstart
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2007-03-27
  • Updated: 2010-09-17
  • Resolved: 2008-04-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 6 JDK 7
6u10 b21Fixed 7Fixed
Description
FULL PRODUCT VERSION :
Java(TM) SE Runtime Environment (build 1.6.0-dp-b88-34)
Java HotSpot(TM) Client VM (build 1.6.0-b88-17-release, mixed mode, sharing)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]
Darwin omybook.local 8.9.1 Darwin Kernel Version 8.9.1: Thu Feb 22 20:55:00 PST 2007; root:xnu-792.18.15~1/RELEASE_I386 i386 i386

A DESCRIPTION OF THE PROBLEM :
The SUN standard implementation of javax.jnlp.PersistenceService API uses an internal fixed size array for storing the storage entries, size 255.

When you try to add a 256th entry, with "PersistenceService.create(URL url, long length)", it fails horribly with an ArrayIndexOutOfBoundsException.

The API contract describes clearly the size limits the PersistenceService should enforce, both for the single file and the whole storage area, but fails to mention completely such a harsh 'number of storage entries' limit, which is moreover unneeded and useless, given the already present size limits, and therefore there is no need to limit the number of files as well.

Also, this bug is very easily fixable by replacing the given fixed size array, with a simple ArrayList, with no consequences on performances or features, except giving a more capable, working as intended, PersistenceService implementation.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create 256 storage entries with the JNLP PersistenceService standard sun implementation


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The entries get created properly, as per API specifications.
ACTUAL -
The 256th PersistenceService.create(URL url, long size) fails horribly with a dreaded ArrayIndexOutOfBoundsException.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
Exception: java.lang.ArrayIndexOutOfBoundsException: 255

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.net.URL;
import java.util.Random;

import javax.jnlp.BasicService;
import javax.jnlp.PersistenceService;
import javax.jnlp.ServiceManager;
import javax.swing.JFrame;
import javax.swing.JTextField;

public class JNLPTester {

	private static PersistenceService persistenceService;
	private static BasicService basicService;
	private static URL codebase;
	
	static {
		try {
			// Get PersistenceService for operations, BasicService for codebase
			persistenceService = (PersistenceService) ServiceManager.lookup("javax.jnlp.PersistenceService");
			basicService = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
			codebase = basicService.getCodeBase();

			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {

		int counter = 0;
		
		try {
			
			for (String url : persistenceService.getNames(codebase)) {
				persistenceService.delete(new URL(codebase, url));
			}
			
			Random random = new Random();

			while (true) {

				// Loop and create a new storage entity with a random name
				URL url = new URL(codebase, "" + random.nextLong());
				persistenceService.create(url, 0L); // zero-length
				counter++;
			}

		} catch (Exception e) {
			JFrame frame = new JFrame();
			frame.add(new JTextField("Counter: " + counter + " - Exception: " + e + " - Message: " + e.getMessage() ));
			frame.setVisible(true);
		}
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
No workaround possible

Comments
EVALUATION easy to fix in Cache.java
25-02-2008