Mantis Bugtracker

Viewing Issue Simple Details Jump to Notes ] View Advanced ] Issue History ] Print ]
ID Category Severity Reproducibility Date Submitted Last Update
0002657 [Quercus] major always 05-09-08 14:59 05-29-08 19:29
Reporter skleinjung View Status public  
Assigned To ferg
Priority normal Resolution fixed  
Status closed   Product Version 3.1.6
Summary 0002657: PHP foreach fails when iterating over a Java list: java.lang.InstantiationException
Description The JavaListAdapter's copy() method is implemented by retrieving the Java class of the underlying list object and calling the newInstance method of that class. This operation fails if the list implementation does not have an accessible no-arg constructor, which is the case for many standard List implementations such as java.util.Collections.UnmodifiableRandomAccessList and java.util.Arrays.ArrayList.
Because the ForeachStatement's execute method uses the Value's copy implementation, attempts to iterate over these list types using foreach fails. The stack trace for this failure is included in the Additional Information section of this report.

I am attaching a war file that illustrates this issue. Deploy it to Resin version 3.1.6 and load it's index.php page to see the error.
Additional Information com.caucho.quercus.QuercusRuntimeException: java.lang.InstantiationException: java.util.Collections$UnmodifiableRandomAccessList
        at com.caucho.quercus.env.JavaListAdapter.copy(
        at com.caucho.quercus.program.ForeachStatement.execute(
        at com.caucho.quercus.program.BlockStatement.execute(
        at com.caucho.quercus.program.QuercusProgram.execute(
        at com.caucho.quercus.servlet.ResinQuercusServlet.service(
        at com.caucho.quercus.servlet.QuercusServlet.service(
        at javax.servlet.http.HttpServlet.service(
        at com.caucho.server.dispatch.ServletFilterChain.doFilter(
        at com.partslogistics.web.servlet.OpenSessionInViewFilter.doFilter(
        at com.partslogistics.web.servlet.OpenSessionInViewFilter$$FastClassByCGLIB$$71be6d7d.invoke(<generated>)
        at net.sf.cglib.proxy.MethodProxy.invoke(
        at org.springframework.aop.framework.Cglib2AopProxy$CglibMethodInvocation.invokeJoinpoint(
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(
        at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(
        at com.partslogistics.web.servlet.OpenSessionInViewFilter$$EnhancerByCGLIB$$7e85867f.doFilter(<generated>)
        at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(
        at org.springframework.web.filter.DelegatingFilterProxy.doFilter(
        at com.caucho.server.dispatch.FilterFilterChain.doFilter(
        at com.caucho.server.webapp.WebAppFilterChain.doFilter(
        at com.caucho.server.dispatch.ServletInvocation.service(
        at com.caucho.server.http.HttpRequest.handleRequest(
        at com.caucho.util.ThreadPool$Item.runTasks(
        at com.caucho.util.ThreadPool$
Caused by: java.lang.InstantiationException: java.util.Collections$UnmodifiableRandomAccessList
        at java.lang.Class.newInstance0(
        at java.lang.Class.newInstance(
        at com.caucho.quercus.env.JavaListAdapter.copy(
        ... 28 more
Attached Files  list-bug.war [^] (891 bytes) 05-09-08 14:59
 JavaListAdapter.class [^] (5,717 bytes) 05-09-08 15:04

- Relationships

- Notes
05-09-08 15:04

In order to fix this issue, the copy method of JavaListAdapter needs to use a different method of instantiating the copy. One possibility is to simply use a pre-selected list implementation. This is done by replacing line 248 of com.caucho.quercus.env.JavaListAdapter with something like the following:

List list = new java.util.ArrayList();

I am successfully using this as a workaround for my application for the time being. However, I do not have enough information about how Quercus is implemented to know if this is a safe general-purpose solution or not. I am, however, attaching a patched version of the JavaListAdapter class file in case anyone else with this problem wants to try it as well.

- Issue History
Date Modified Username Field Change
05-09-08 14:59 skleinjung New Issue
05-09-08 14:59 skleinjung File Added: list-bug.war
05-09-08 14:59 skleinjung Issue Monitored: skleinjung
05-09-08 15:04 skleinjung Note Added: 0003040
05-09-08 15:04 skleinjung File Added: JavaListAdapter.class
05-29-08 19:29 ferg Assigned To  => ferg
05-29-08 19:29 ferg Status new => closed
05-29-08 19:29 ferg Resolution open => fixed
05-29-08 19:29 ferg Fixed in Version  => 3.2.0

Mantis 1.0.0rc3[^]
Copyright © 2000 - 2005 Mantis Group
32 total queries executed.
26 unique queries executed.
Powered by Mantis Bugtracker