Captive Imagination
September 06, 2010, 08:41:09 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: jSeamless 1.0 Beta 7 is Available http://www.jseamless.org
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: patch for two NPE  (Read 304 times)
0 Members and 1 Guest are viewing this topic.
Nicolas
Newbie
*
Offline Offline

Posts: 2


View Profile
« on: January 02, 2010, 10:57:49 AM »

Hello,

I'm playing a bit with JGN and it looks nice...

I ran into a NullPointerException using SharedObjects with Lists and Maps. The reason for that is the class information that is passed into the converters is null. I have added the class information into the serialization stream and that fixes the problem.

Code:
Index: CollectionConverter.java
===================================================================
--- CollectionConverter.java (revision 1287)
+++ CollectionConverter.java (working copy)
@@ -18,6 +18,7 @@
 public class CollectionConverter extends Converter {
  public void writeObjectData (MessageClient client, Object object, ByteBuffer buffer) throws ConversionException {
  Collection collection = (Collection)object;
+ Converter.writeClass(client, collection.getClass(), buffer);
  int length = collection.size();
  BufferUtil.writeInt(buffer, length);
  if (length == 0) return;
@@ -46,8 +47,9 @@
  }
 
  public <T> T readObjectData (ByteBuffer buffer, Class<T> c) throws ConversionException {
+ Collection collection = (Collection)newInstance(Converter.readClass(buffer));
  int length = BufferUtil.readInt(buffer);
- Collection collection = (Collection)newInstance(c);
+ //Collection collection = (Collection)newInstance(c);
  if (length == 0) return (T)collection;
  if (buffer.get() == 1) {
  Class elementClass = Converter.readClass(buffer);
@@ -60,5 +62,5 @@
  }
  return (T)collection;
  }
-
+
 }
Index: MapConverter.java
===================================================================
--- MapConverter.java (revision 1287)
+++ MapConverter.java (working copy)
@@ -22,6 +22,7 @@
 public class MapConverter extends Converter {
  public void writeObjectData (MessageClient client, Object object, ByteBuffer buffer) throws ConversionException {
  Map<Object, Object> map = (Map)object;
+ Converter.writeClass(client, map.getClass(), buffer);
  int length = map.size();
  BufferUtil.writeInt(buffer, length);
  if (length == 0) return;
@@ -72,7 +73,8 @@
  }
 
  public <T> T readObjectData (ByteBuffer buffer, Class<T> c) throws ConversionException {
- Map map = (Map)newInstance(c);
+ Map map = (Map)newInstance(Converter.readClass(buffer));
+ //Map map = (Map)newInstance(c);
  int length = BufferUtil.readInt(buffer);
  if (length == 0) return (T)map;
  // Read element types and get converters.
Logged
Tumaini
JGN Developer
Jr. Member
*****
Offline Offline

Posts: 51


View Profile
« Reply #1 on: January 08, 2010, 05:03:00 AM »

Thanks!
I'm not very well versed in SharedObjects so I'm hoping someone else here can have a look and apply it, otherwise I'll do it myself when I get the opportunity.
Hope JGN is a good help for you otherwise!
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.158 seconds with 21 queries.