Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 247701

Summary: JavaFieldJDOMAdapter causing StringIndexOutOfBoundsException
Product: [WebTools] WTP Java EE Tools Reporter: Carl Anderson <ccc>
Component: jst.jemAssignee: Carl Anderson <ccc>
Status: RESOLVED FIXED QA Contact: Chuck Bridgham <cbridgha>
Severity: major    
Priority: P3 Flags: cbridgha: review+
Version: 1.5.5   
Target Milestone: 1.5.5 P   
Hardware: PC   
OS: Windows XP   
Whiteboard:
Bug Depends on:    
Bug Blocks: 247732    
Attachments:
Description Flags
Check to make sure the initializer is for this variable none

Description Carl Anderson CLA 2008-09-17 14:01:24 EDT
The steps to reproduce are simple- create a Servlet or an EJB, and in the Java class, add a multi-variable declaration with one of the latter variables having an initializer, such as:

int value, value2 = 999;

When JEM performs the inspection of the Java class, an exception like the following will occur:

+++ Warning +++: Mon Jun 23 13:26:08 EDT 2008 java.lang.StringIndexOutOfBoundsException
at java.lang.String.substring(String.java:1088)
at org.eclipse.jem.internal.adapters.jdom.JavaFieldJDOMAdaptor.getFieldInitializerString(JavaFieldJDOMAdaptor.java:131)
at org.eclipse.jem.internal.adapters.jdom.JavaFieldJDOMAdaptor.setModifiers(JavaFieldJDOMAdaptor.java:247)
at org.eclipse.jem.internal.adapters.jdom.JavaFieldJDOMAdaptor.reflectValues(JavaFieldJDOMAdaptor.java:234)
at org.eclipse.jem.internal.java.adapters.ReflectionAdaptor.reflectValuesIfNecessary(ReflectionAdaptor.java:143)
at org.eclipse.jem.internal.java.adapters.JavaReflectionAdaptor.reflectValuesIfNecessary(JavaReflectionAdaptor.java:260)
at org.eclipse.jem.java.internal.impl.FieldImpl.reflectValues(FieldImpl.java:240)
at org.eclipse.jem.java.internal.impl.FieldImpl.isTransient(FieldImpl.java:203)
at org.eclipse.jst.j2ee.model.internal.validation.ASessionBeanClassVRule.validateTransientField(ASessionBeanClassVRule.java:25)
at org.eclipse.jst.j2ee.model.internal.validation.ABeanClassVRule.validate(ABeanClassVRule.java:409)
at org.eclipse.jst.j2ee.model.internal.validation.ATypeVRule.validate(ATypeVRule.java:129)
at org.eclipse.jst.j2ee.model.internal.validation.ATypeVRule.validate(ATypeVRule.java:83)
at org.eclipse.jst.j2ee.model.internal.validation.AbstractEJBValidator.run(AbstractEJBValidator.java:133)
at org.eclipse.jst.j2ee.model.internal.validation.EJBValidator.fullValidate(EJBValidator.java:418)
at org.eclipse.jst.j2ee.model.internal.validation.EJBValidator.commonValidate(EJBValidator.java:80)
at org.eclipse.jst.j2ee.model.internal.validation.EJBValidator.validateInJob(EJBValidator.java:104)
at org.eclipse.jst.j2ee.internal.ejb.workbench.validation.UIEjbValidator.validateInJob(UIEjbValidator.java:51)
at org.eclipse.wst.validation.internal.operations.ValidatorJob.run(ValidatorJob.java:72)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:58)
Comment 1 Carl Anderson CLA 2008-09-17 14:24:09 EDT
Created attachment 112804 [details]
Check to make sure the initializer is for this variable

The code correctly identifies that the end of the variable declaration is the comma, and correctly locates the equals sign, but does not check to make sure that the equals sign is before the end of the variable declaration.  Thus, when substring is called, the first value is larger than the second value, and thus the StringIndexOutOfBoundsException occurs.

Also, please note that this initialization is valid syntax, and that the initialization is only for the variable next to the equals sign (and not the entire list of variables).
Comment 2 Chuck Bridgham CLA 2008-09-21 15:12:10 EDT
approve - simple fix
Comment 3 Carl Anderson CLA 2008-09-25 11:55:21 EDT
This change was committed to R1_5_5_patches on 9/24.