# Ich raff es nicht . NotSerializableException



## Tobias (2. Okt 2007)

Hi,

ich sehe - glaube ich - den Wald vor lauter Bäumen nicht ...

Ich habe eine simple stateless SessionBean, welche eine Methode getAvailableIndices() besitzt, die eine ArrayList<?extends IndexInfo> zurückgibt. Wenn ich diese Methode aufrufe, fliegt immer folgende Exception:


```
Exception in thread "AWT-EventQueue-0" java.lang.reflect.UndeclaredThrowableException
	at $Proxy1.getIndexList(Unknown Source)
	at de.tobiasdemuth.cube.frontoffice.gui.SearchDialog.loadAvailableIndices(SearchDialog.java:160)
	at de.tobiasdemuth.cube.frontoffice.gui.SearchDialog.<init>(SearchDialog.java:87)
	at de.tobiasdemuth.cube.frontoffice.gui.MainFrame$SearchActionListener.actionPerformed(MainFrame.java:132)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.rmi.MarshalException: Failed to communicate.  Problem during marshalling/unmarshalling; nested exception is: 
	java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: de.tobiasdemuth.cube.server.search.SearchServiceBean
	at org.jboss.remoting.transport.socket.SocketClientInvoker.handleException(SocketClientInvoker.java:122)
	at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:644)
	at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
	at org.jboss.remoting.Client.invoke(Client.java:1550)
	at org.jboss.remoting.Client.invoke(Client.java:530)
	at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
	... 28 more
Caused by: java.io.WriteAbortedException: writing aborted; java.io.NotSerializableException: de.tobiasdemuth.cube.server.search.SearchServiceBean
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at java.util.ArrayList.readObject(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeReadObject(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at org.jboss.aop.joinpoint.InvocationResponse.readExternal(InvocationResponse.java:122)
	at java.io.ObjectInputStream.readExternalData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
	at java.io.ObjectInputStream.readSerialData(Unknown Source)
	at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
	at java.io.ObjectInputStream.readObject0(Unknown Source)
	at java.io.ObjectInputStream.readObject(Unknown Source)
	at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObjectVersion2_2(JavaSerializationManager.java:239)
	at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:133)
	at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:120)
	at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.versionedRead(MicroSocketClientInvoker.java:943)
	at org.jboss.remoting.transport.socket.MicroSocketClientInvoker.transport(MicroSocketClientInvoker.java:584)
	at org.jboss.remoting.MicroRemoteClientInvoker.invoke(MicroRemoteClientInvoker.java:122)
	at org.jboss.remoting.Client.invoke(Client.java:1550)
	at org.jboss.remoting.Client.invoke(Client.java:530)
	at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:62)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:53)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:72)
	at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
	at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:103)
	at $Proxy1.getIndexList(Unknown Source)
	at de.tobiasdemuth.cube.frontoffice.gui.SearchDialog.loadAvailableIndices(SearchDialog.java:160)
	at de.tobiasdemuth.cube.frontoffice.gui.SearchDialog.<init>(SearchDialog.java:87)
	at de.tobiasdemuth.cube.frontoffice.gui.MainFrame$SearchActionListener.actionPerformed(MainFrame.java:132)
	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
	at java.awt.Component.processMouseEvent(Unknown Source)
	at javax.swing.JComponent.processMouseEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Window.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
	at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:74)
	... 36 more
Caused by: java.io.NotSerializableException: de.tobiasdemuth.cube.server.search.SearchServiceBean
	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
	at java.io.ObjectOutputStream.writeObject(Unknown Source)
	at java.util.ArrayList.writeObject(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
	at java.io.ObjectOutputStream.writeObject(Unknown Source)
	at org.jboss.aop.joinpoint.InvocationResponse.writeExternal(InvocationResponse.java:101)
	at java.io.ObjectOutputStream.writeExternalData(Unknown Source)
	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
	at java.io.ObjectOutputStream.defaultWriteFields(Unknown Source)
	at java.io.ObjectOutputStream.writeSerialData(Unknown Source)
	at java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
	at java.io.ObjectOutputStream.writeObject(Unknown Source)
	at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.sendObjectVersion2_2(JavaSerializationManager.java:120)
	at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.sendObject(JavaSerializationManager.java:95)
	at org.jboss.remoting.marshal.serializable.SerializableMarshaller.write(SerializableMarshaller.java:120)
	at org.jboss.remoting.transport.socket.ServerThread.versionedWrite(ServerThread.java:792)
	at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:592)
	at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:369)
	at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:165)
```

Ich weiß nicht, was er da serialisieren will! ArrayList ist Serializable, IndexInfo ist Serializable, was will er denn noch? Zur Sicherheit mal noch meine Interfaces und die Bean:

IndexInfo.java:

```
public interface IndexInfo extends Serializable {
	
	public String getDeclaringPluginId();
	
	public String getName();
	
	public String getDescription();

}
```

SearchService.java:

```
@Remote
public interface SearchService {
	
	public List<? extends IndexInfo> getIndexList();

}
```

und die Bean SearchServiceBean.java:

```
@Stateless
public class SearchServiceBean implements SearchService {
	
	private class MyIndexInfo implements IndexInfo, Serializable {
		
		private String pluginId;
		
		private String name;
		
		private String description;
		
		public MyIndexInfo(String name, String description, String pluginId) {
			this.name = name;
			this.description = description;
			this.pluginId = pluginId;
		}

		/*
		 * @see de.tobiasdemuth.cube.common.search.IndexInfo#getDeclaringPluginId()
		 */
		public String getDeclaringPluginId() {
			return pluginId;
		}

		/*
		 * @see de.tobiasdemuth.cube.common.search.IndexInfo#getDescription()
		 */
		public String getDescription() {
			return description;
		}

		/*
		 * @see de.tobiasdemuth.cube.common.search.IndexInfo#getName()
		 */
		public String getName() {
			return name;
		}
		
	}

	/**
	 * @see de.tobiasdemuth.cube.server.search.SearchService#getIndexList()
	 */
	public ArrayList<? extends IndexInfo> getIndexList() {
		ArrayList<MyIndexInfo> fakeIndices = new ArrayList<MyIndexInfo>();
		fakeIndices.add(new MyIndexInfo("fake1", "fakeIndex1", "fakePlugin"));
		fakeIndices.add(new MyIndexInfo("fake2", "fakeIndex2", "fakePlugin"));
		fakeIndices.add(new MyIndexInfo("fake3", "fakeIndex3", "fakePlugin"));
		return fakeIndices;
	}

}
```

Bitte helft mir, ich komme mir so doof vor!

mpG
Tobias


----------



## SlaterB (2. Okt 2007)

man bist du doof 

steht doch da: SearchServiceBean ist nicht Serialisierbar (implementiert nicht das Interface)
alle dein Subklassen implementieren schön das Interface (vielleicht gar nicht nötig), aber SearchServiceBean nicht..


----------



## Tobias (2. Okt 2007)

"Jetzt geht er ... NE, DER GEHT!" :shock:  :?   

Aber warum? Ich hab meine Beans doch sonst auch nicht mit Serializable auszeichnen müssen?!?

mpG
Tobias


----------



## maki (2. Okt 2007)

> Aber warum? Ich hab meine Beans doch sonst auch nicht mit Serializable auszeichnen müssen?!?


Hast du sonst auch innere Klassen benutzt?

Ziemlich schräg, da muss die ganze EJB serialisiert werden...


----------



## Tobias (2. Okt 2007)

Toll, meine Vereinfachung aus Testzwecken hat es also komplizierter gemacht. *kopfschüttel*
Danke an alle Beteiligten!

mpG
Tobias


----------



## maki (2. Okt 2007)

innere Klassen in EJBs sind Pfui


----------

