United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6539564 com.sun.jnlp.PersistenceServiceImpl fires a ArrayIndexOutOfBoundsException
JDK-6539564 : com.sun.jnlp.PersistenceServiceImpl fires a ArrayIndexOutOfBoundsException

Details
Type:
Bug
Submit Date:
2007-03-27
Status:
Closed
Updated Date:
2010-09-17
Project Name:
JDK
Resolved Date:
2008-04-03
Component:
deploy
OS:
windows_xp
Sub-Component:
webstart
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:
6u10 (b21)

Related Reports
Backport:

Sub Tasks

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
                                     
2008-02-25



Hardware and Software, Engineered to Work Together