NullPointerException in Table.class of vaadin api

These lines of code from Vadin ApI 6.8.12 giving me exception.


 /*
         * Send the page buffer indexes to ensure that the client side stays in
         * sync. Otherwise we _might_ have the situation where the client side
         * discards too few or too many rows, causing out of sync issues.
         */
        int pageBufferLastIndex = pageBufferFirstIndex
                + pageBuffer[CELL_ITEMID]
.length - 1;
        target.addAttribute(VScrollTable.ATTRIBUTE_PAGEBUFFER_FIRST,
                pageBufferFirstIndex);
        target.addAttribute(VScrollTable.ATTRIBUTE_PAGEBUFFER_LAST,
                pageBufferLastIndex);

this is the exception


Sep 18, 2013 5:01:10 PM com.vaadin.Application terminalError
SEVERE: Terminal error:
java.lang.NullPointerException
	at com.vaadin.ui.Table.paintContent(Table.java:3032)
	at com.vaadin.ui.AbstractComponent.paint(AbstractComponent.java:781)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.writeUidlResponce(AbstractCommunicationManager.java:1044)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.paintAfterVariableChanges(AbstractCommunicationManager.java:925)
	at com.vaadin.terminal.gwt.server.AbstractCommunicationManager.doHandleUidlRequest(AbstractCommunicationManager.java:792)
	at com.vaadin.terminal.gwt.server.CommunicationManager.handleUidlRequest(CommunicationManager.java:325)
	at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:501)
	at org.vaadin.artur.icepush.ICEPushServlet.service(ICEPushServlet.java:72)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:724)

line 7 is pointed in stacktrace i.e int pageBufferLastIndex line

When is it giving you exceptions? …because that’s not normal behavior. It should come from something that you’re doing.

It seems you’re using ICEPush. If you have background threads that access/modify the UI state, please check that you have proper synchronization in place. In Vaadin 6, you should do


synchronized(myApplicationInstance) {
    // access UI components
}

yes i am using ICEPUSH . but there is no background thread. so kindly point me where should i use synchronization block. my code looks like this


public class MainMedMaxApplication extends Application
{
    public static CopyOnWriteArrayList<MainMedMaxApplication> appList=new CopyOnWriteArrayList<MainMedMaxApplication>();
    private ICEPush pusher = new ICEPush();
    private Table tbl = new Table();
       @Override
	public void init() 
	{
			setMainWindow(new Window("MediMax Dashboard"));
			System.out.println("---->>> Init()");
			getMainWindow().setContent(mainLayout);
			setTable()//this will set the Table component
			appList.add(this);	
                       getMainWindow().addComponent(pusher);
                      loadTable()//this will load the contents of table 
		
		
	}
	public  void loadTabl(String date) 
	{
             // first remove any previous data in container
            // add data from databse to indexed container
         }
        private void registerListeners()
        {
         //add value change listners over table and some other listeners and when any listeners triges i save the changed data in database then i call the following finction.
            public void tbl.addListener(//value change listener)
              {
//save data in db
//update table on all running instances of tables on different matchines by calling this method
                synchronizePortlets();
             }
        }

        public void synchronizePortlets() 
		{
				// TODO Auto-generated method stub
			
				Iterator<MainMedMaxApplication>itM = MainMedMaxApplication.appList.iterator();
				while(itM.hasNext())
				{
					MainMedMaxApplication app = itM.next();
					if(app!=this.app)
					{
							app.loadTabl(getDate());
							app.getPusher().push();
						
					}
				}
			
		}
}

The “update table on all running instances” part is probably it because when you execute something one an instance for which the request came from another instance (where the listener got called) you’re technically updating it in a background thread and as a result have to synchronize to the application.

Ok i modify my cod of synchronizeportlets() like this. it did not raises any more exception but now app go in to out of sync red error and some time a red circle start spinning over right corner and never stops.


public void synchronizePortlets()
        {
                // TODO Auto-generated method stub
            
                Iterator<MainMedMaxApplication>itM = MainMedMaxApplication.appList.iterator();
                while(itM.hasNext())
                {
                    MainMedMaxApplication app = itM.next();
                   
                         synchronized(app)
                         {
                            app.loadTabl(getDate());
                            app.getPusher().push();
                          }
                        
                    
                }
            
        }

Could it be that e.g. a request from one portlet triggers others to refresh, which in turn causes an event that causes all others to refresh etc?

The synchronization looks correct assuming it is not possible for appList to change while it is being iterated over. Otherwise, you should use some thread safe method to copy the list just before iteration and iterate over the copy, checking that the applications are still “alive” at the time you process each in the loop.

I am using as mentioned above CopyOnWriteArrayList which internally do exactly as you mentioned. And it is 100% sure the app objects in list is actually exists, and not null. because on login we add it to the appList and on logout user we remover the app object from the list.

Yes actually we want to refresh all opened tables on different instances opened over different browsers when any instance’s table state changed. Now What i did, i add value Change event on table, and when value change in table there two things happened.
1 is to save changed data in Db.
2 is to Push this change on all alive running application instances.

But here some times i caught in different errors, i.e some times concurrentModificationException, or out of synch, or red circle (Progress indicator) spinning over top right corner and never stop.

after applying synchronized block Concurrent Modification is not any more bothering me :slight_smile: But application freezes when red spinning circle appears. what should i do now? any help. please if any other solution available?

I’m not sure if it would help but you could try using
this technique
to call a method for all users and then just execute table.refreshrowcache. This might cause less bugs/synchronization issues.

on reload every table of any instance has to be reloaded from database. refereshRowCache did’t work.

then what about just refresh() as described
here
?

Did my suggestion of using the Broadcastlistener work in the way that it didn’t block the app?

do i have to push on every instance of applist or just on my instance after calling BroadCaster.broadcast(“staff-doctor-dash-loadTable”);

it did not work. ichange my code like this


public void synchronizePortlets() 
{
	// TODO Auto-generated method stub
	BroadCaster.broadcast("staff-doctor-dash-loadTable");
        this.getApp().getPusher().push();
}

and 
public void receiveBroadcast(String message) 
{
		// TODO Auto-generated method stub
		if(message.equals("staff-doctor-dash-loadTable"))
		{
			loadTabl(getDate());
		}
}

If you use automatic push you shouldn’t have to do anything else but if you set it to manual you have to UI.push in the run method of the runnable inside the receiveupload method. If you’re having problems broadcasting to all the users you could test it by adding System.out.println(“broadcast”) to the run method and see if it gets called x times where x is the amount of UI instances.

basicaly i am using vaadin 6.8.12 so i have to use IcePush addon