Java Code Examples for java.io.NotSerializableException

The following examples show how to use java.io.NotSerializableException. These examples are extracted from open source projects.
Example 1
Project: activemq-artemis   File: JGroupsServerLocatorSchema.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected URI internalNewURI(ServerLocator bean) throws Exception {
   DiscoveryGroupConfiguration dgc = bean.getDiscoveryGroupConfiguration();
   BroadcastEndpointFactory endpoint = dgc.getBroadcastEndpointFactory();
   String auth;
   if (endpoint instanceof JGroupsFileBroadcastEndpointFactory) {
      auth = ((JGroupsFileBroadcastEndpointFactory) endpoint).getChannelName();
   } else if (endpoint instanceof JGroupsPropertiesBroadcastEndpointFactory) {
      auth = ((JGroupsPropertiesBroadcastEndpointFactory) endpoint).getChannelName();
   } else {
      throw new NotSerializableException(endpoint + "not serializable");
   }
   String query = BeanSupport.getData(null, bean, dgc, endpoint);
   dgc.setBroadcastEndpointFactory(endpoint);
   return new URI(SchemaConstants.JGROUPS, null, auth, -1, null, query, null);
}
 
Example 2
Project: ignite   File: CacheEntryProcessorNonSerializableTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param node Grid node.
 * @param cache Node cache.
 * @param txConcurrency Transaction concurrency.
 * @param txIsolation Transaction isolation.
 */
@SuppressWarnings({"unchecked", "ThrowableNotThrown"})
private void checkTxInvoke(Ignite node, IgniteCache cache, TransactionConcurrency txConcurrency,
    TransactionIsolation txIsolation) {
    try (final Transaction tx = node.transactions().txStart(txConcurrency, txIsolation)) {
        cache.put(KEY, WRONG_VALUE);

        cache.invoke(KEY, new NonSerialazibleEntryProcessor());

        GridTestUtils.assertThrowsWithCause(new Callable<Object>() {
            @Override public Object call() {
                tx.commit();

                return null;
            }
        }, NotSerializableException.class);
    }
}
 
Example 3
Project: gemfirexd-oss   File: FunctionStreamingReplyMessage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void fromData(DataInput in) throws IOException, ClassNotFoundException {
  super.fromData(in);
  this.msgNum = in.readInt();
  this.processorId = in.readInt();
  try {
    this.result = DataSerializer.readObject(in);
    byte flags = in.readByte();
    this.lastMsg = (flags & IS_LAST) != 0;
    if ((flags & HAS_TX_CHANGES) != 0) {
      this.txChanges = TXChanges.fromData(in);
    }
  }
  catch (Exception e) { // bug fix 40670
    // Seems odd to throw a NonSerializableEx when it has already been
    // serialized and we are failing because we can't deserialize.
    NotSerializableException ioEx = new NotSerializableException();
    ioEx.initCause(e);
    throw ioEx;
  }
}
 
Example 4
Project: AsuraFramework   File: StdJDBCDelegate.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Remove the transient data from and then create a serialized <code>java.util.ByteArrayOutputStream</code>
 * version of a <code>{@link org.quartz.JobDataMap}</code>.
 * </p>
 * 
 * @param data
 *          the JobDataMap to serialize
 * @return the serialized ByteArrayOutputStream
 * @throws IOException
 *           if serialization causes an error
 */
protected ByteArrayOutputStream serializeJobData(JobDataMap data)
    throws IOException {
    if (canUseProperties()) {
        return serializeProperties(data);
    }

    try {
        return serializeObject(data);
    } catch (NotSerializableException e) {
        throw new NotSerializableException(
            "Unable to serialize JobDataMap for insertion into " + 
            "database because the value of property '" + 
            getKeyOfNonSerializableValue(data) + 
            "' is not serializable: " + e.getMessage());
    }
}
 
Example 5
Project: gemfirexd-oss   File: PdxSerializableJUnitTest.java    License: Apache License 2.0 6 votes vote down vote up
public void testBasicAll() throws IOException, ClassNotFoundException {
  BasicAllFieldTypes v1 = new BasicAllFieldTypes(0x1020304050607080L, false);
  try {
    serializeAndDeserialize(v1);
    fail("expected NotSerializableException");
  } catch (NotSerializableException expected) {

  }
  this.c.setPdxSerializer(new BasicAllFieldTypesPdxSerializer());
  try {
    BasicAllFieldTypes v2 = (BasicAllFieldTypes) serializeAndDeserialize(v1);
    assertEquals(v1, v2);
  } finally {
    this.c.setPdxSerializer(null);
  }
}
 
Example 6
Project: gemfirexd-oss   File: DistributionChannel.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return list of recipients who did not receive the message because
 * they left the view (null if all received it or it was sent to
 * {@link DistributionMessage#ALL_RECIPIENTS}).
 * @throws NotSerializableException
 *         If content cannot be serialized
 */
public Set send(InternalDistributedMember[] destinations,
                DistributionMessage content,
                DistributionManager dm, DistributionStats stats)
throws NotSerializableException {
  if (membershipManager == null) {
    logger.warning(LocalizedStrings.DistributionChannel_ATTEMPTING_A_SEND_TO_A_DISCONNECTED_DISTRIBUTIONMANAGER);
    if (destinations.length == 1 
        && destinations[0] == DistributionMessage.ALL_RECIPIENTS)
      return null;
    HashSet result = new HashSet();
    for (int i = 0; i < destinations.length; i ++)
      result.add(destinations[i]);
    return result;
    }
  return membershipManager.send(destinations, content, stats);
}
 
Example 7
Project: hottub   File: CertPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example 8
Project: quickperf   File: TestIssueRepository.java    License: Apache License 2.0 5 votes vote down vote up
private void manageSavingIssue(TestIssue testIssue, String workingFolderPath, IllegalStateException illegalStateException) {
    Throwable cause = illegalStateException.getCause();
    if (cause instanceof NotSerializableException) {
        TestIssue serializableTestIssue =
                TestIssue.buildSerializableTestIssueFrom(testIssue);
        save(serializableTestIssue, workingFolderPath);
    } else {
        throw illegalStateException;
    }
}
 
Example 9
Project: hottub   File: SerializedLambdaTest.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void assertNotSerial(Predicate<String> p, Consumer<Predicate<String>> asserter)
        throws IOException, ClassNotFoundException {
    asserter.accept(p);
    try {
        byte[] bytes = serialize(p);
        fail("Expected serialization failure");
    }
    catch (NotSerializableException e) {
        // success
    }
}
 
Example 10
Project: jdk8u-jdk   File: CertPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example 11
Project: beam   File: ProxyInvocationHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void writeObject(java.io.ObjectOutputStream stream) throws IOException {
  throw new NotSerializableException(
      "PipelineOptions objects are not serializable and should not be embedded into transforms "
          + "(did you capture a PipelineOptions object in a field or in an anonymous class?). "
          + "Instead, if you're using a DoFn, access PipelineOptions at runtime "
          + "via ProcessContext/StartBundleContext/FinishBundleContext.getPipelineOptions(), "
          + "or pre-extract necessary fields from PipelineOptions "
          + "at pipeline construction time.");
}
 
Example 12
Project: openjdk-jdk8u   File: PinLastArguments.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6332349\n");

    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;

    // Might require multiple calls to System.gc() for weak-references
    // processing to be complete. If the weak-reference is not cleared as
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }

    System.err.println("TEST PASSED");
}
 
Example 13
Project: jdk1.8-source-analysis   File: ClientNotifForwarder.java    License: Apache License 2.0 5 votes vote down vote up
private NotificationResult fetchNotifs() {
    try {
        NotificationResult nr = ClientNotifForwarder.this.
            fetchNotifs(clientSequenceNumber,maxNotifications,
                        timeout);

        if (logger.traceOn()) {
            logger.trace("NotifFetcher-run",
                         "Got notifications from the server: "+nr);
        }

        return nr;
    } catch (ClassNotFoundException | NotSerializableException | UnmarshalException e) {
        logger.trace("NotifFetcher.fetchNotifs", e);
        return fetchOneNotif();
    } catch (IOException ioe) {
        if (!shouldStop()) {
            logger.error("NotifFetcher-run",
                         "Failed to fetch notification, " +
                         "stopping thread. Error is: " + ioe, ioe);
            logger.debug("NotifFetcher-run",ioe);
        }

        // no more fetching
        return null;
    }
}
 
Example 14
Project: jdk8u-dev-jdk   File: CertPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example 15
Project: dragonwell8_jdk   File: CertPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example 16
Project: jdk8u_jdk   File: CertPath.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example 17
Project: jdk8u-jdk   File: ClientNotifForwarder.java    License: GNU General Public License v2.0 5 votes vote down vote up
private NotificationResult fetchNotifs() {
    try {
        NotificationResult nr = ClientNotifForwarder.this.
            fetchNotifs(clientSequenceNumber,maxNotifications,
                        timeout);

        if (logger.traceOn()) {
            logger.trace("NotifFetcher-run",
                         "Got notifications from the server: "+nr);
        }

        return nr;
    } catch (ClassNotFoundException | NotSerializableException | UnmarshalException e) {
        logger.trace("NotifFetcher.fetchNotifs", e);
        return fetchOneNotif();
    } catch (IOException ioe) {
        if (!shouldStop()) {
            logger.error("NotifFetcher-run",
                         "Failed to fetch notification, " +
                         "stopping thread. Error is: " + ioe, ioe);
            logger.debug("NotifFetcher-run",ioe);
        }

        // no more fetching
        return null;
    }
}
 
Example 18
Project: dragonwell8_jdk   File: CClipboard.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    FlavorTable flavorMap = getDefaultFlavorTable();
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    DataTransferer dataTransferer = DataTransferer.getInstance();
    long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap);
    declareTypes(formatArray, this);

    Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap);
    for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) {
        long format = entry.getKey();
        DataFlavor flavor = entry.getValue();

        try {
            byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);
            setData(bytes, format);
        } catch (IOException e) {
            // Fix 4696186: don't print exception if data with
            // javaJVMLocalObjectMimeType failed to serialize.
            // May remove this if-check when 5078787 is fixed.
            if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                    e instanceof NotSerializableException)) {
                e.printStackTrace();
            }
        }
    }

    notifyChanged();
}
 
Example 19
Project: dragonwell8_jdk   File: PinLastArguments.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6332349\n");

    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;

    // Might require multiple calls to System.gc() for weak-references
    // processing to be complete. If the weak-reference is not cleared as
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }

    System.err.println("TEST PASSED");
}
 
Example 20
Project: Bytecoder   File: InvalidPropertiesFormatException.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Throws NotSerializableException, since InvalidPropertiesFormatException
 * objects are not intended to be serializable.
 */
@java.io.Serial
private void writeObject(java.io.ObjectOutputStream out)
    throws NotSerializableException
{
    throw new NotSerializableException("Not serializable.");
}
 
Example 21
protected Object writeReplace() throws ObjectStreamException {
	if (this.serializationId != null) {
		return new SerializedBeanFactoryReference(this.serializationId);
	}
	else {
		throw new NotSerializableException("DefaultListableBeanFactory has no serialization id");
	}
}
 
Example 22
Project: knopflerfish.org   File: EndpointPermission.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * WriteObject is called to save the state of this permission to a stream.
 * The actions are serialized, and the superclass takes care of the name.
 */
private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException {
	if (endpoint != null) {
		throw new NotSerializableException("cannot serialize");
	}
	// Write out the actions. The superclass takes care of the name
	// call getActions to make sure actions field is initialized
	if (actions == null) {
		getActions();
	}
	s.defaultWriteObject();
}
 
Example 23
Project: jdk8u-jdk   File: CClipboard.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void setContentsNative(Transferable contents) {
    FlavorTable flavorMap = getDefaultFlavorTable();
    // Don't use delayed Clipboard rendering for the Transferable's data.
    // If we did that, we would call Transferable.getTransferData on
    // the Toolkit thread, which is a security hole.
    //
    // Get all of the target formats into which the Transferable can be
    // translated. Then, for each format, translate the data and post
    // it to the Clipboard.
    DataTransferer dataTransferer = DataTransferer.getInstance();
    long[] formatArray = dataTransferer.getFormatsForTransferableAsArray(contents, flavorMap);
    declareTypes(formatArray, this);

    Map<Long, DataFlavor> formatMap = dataTransferer.getFormatsForTransferable(contents, flavorMap);
    for (Map.Entry<Long, DataFlavor> entry : formatMap.entrySet()) {
        long format = entry.getKey();
        DataFlavor flavor = entry.getValue();

        try {
            byte[] bytes = DataTransferer.getInstance().translateTransferable(contents, flavor, format);
            setData(bytes, format);
        } catch (IOException e) {
            // Fix 4696186: don't print exception if data with
            // javaJVMLocalObjectMimeType failed to serialize.
            // May remove this if-check when 5078787 is fixed.
            if (!(flavor.isMimeTypeEqual(DataFlavor.javaJVMLocalObjectMimeType) &&
                    e instanceof NotSerializableException)) {
                e.printStackTrace();
            }
        }
    }

    notifyChanged();
}
 
Example 24
Project: j2objc   File: CertPath.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Replaces the {@code CertPath} to be serialized with a
 * {@code CertPathRep} object.
 *
 * @return the {@code CertPathRep} to be serialized
 *
 * @throws ObjectStreamException if a {@code CertPathRep} object
 * representing this certification path could not be created
 */
protected Object writeReplace() throws ObjectStreamException {
    try {
        return new CertPathRep(type, getEncoded());
    } catch (CertificateException ce) {
        NotSerializableException nse =
            new NotSerializableException
                ("java.security.cert.CertPath: " + type);
        nse.initCause(ce);
        throw nse;
    }
}
 
Example 25
Project: concierge   File: CapabilityPermission.java    License: Eclipse Public License 1.0 5 votes vote down vote up
/**
 * WriteObject is called to save the state of this permission to a stream.
 * The actions are serialized, and the superclass takes care of the name.
 */
private synchronized void writeObject(java.io.ObjectOutputStream s) throws IOException {
	if (bundle != null) {
		throw new NotSerializableException("cannot serialize");
	}
	// Write out the actions. The superclass takes care of the name
	// call getActions to make sure actions field is initialized
	if (actions == null)
		getActions();
	s.defaultWriteObject();
}
 
Example 26
Project: TencentKona-8   File: PinLastArguments.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6332349\n");

    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;

    // Might require multiple calls to System.gc() for weak-references
    // processing to be complete. If the weak-reference is not cleared as
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }

    System.err.println("TEST PASSED");
}
 
Example 27
Project: java-technology-stack   File: AbstractEntityManagerFactoryBean.java    License: MIT License 5 votes vote down vote up
protected Object writeReplace() throws ObjectStreamException {
	if (this.beanFactory != null && this.beanName != null) {
		return new SerializedEntityManagerFactoryBeanReference(this.beanFactory, this.beanName);
	}
	else {
		throw new NotSerializableException("EntityManagerFactoryBean does not run within a BeanFactory");
	}
}
 
Example 28
Project: jdk8u-jdk   File: PinLastArguments.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    System.err.println("\nRegression test for bug 6332349\n");

    Ping impl = new PingImpl();
    Reference<?> ref = new WeakReference<Ping>(impl);
    try {
        Ping stub = (Ping) UnicastRemoteObject.exportObject(impl, 0);
        Object notSerializable = new Object();
        stub.ping(impl, null);
        try {
            stub.ping(impl, notSerializable);
        } catch (MarshalException e) {
            if (e.getCause() instanceof NotSerializableException) {
                System.err.println("ping invocation failed as expected");
            } else {
                throw e;
            }
        }
    } finally {
        UnicastRemoteObject.unexportObject(impl, true);
    }
    impl = null;

    // Might require multiple calls to System.gc() for weak-references
    // processing to be complete. If the weak-reference is not cleared as
    // expected we will hang here until timed out by the test harness.
    while (true) {
        System.gc();
        Thread.sleep(20);
        if (ref.get() == null) {
            break;
        }
    }

    System.err.println("TEST PASSED");
}
 
Example 29
Project: Skript   File: WorldGuardHook.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deserialize(final Fields fields) throws StreamCorruptedException, NotSerializableException {
	final String r = fields.getAndRemoveObject("region", String.class);
	fields.setFields(this);
	
	WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform();
	ProtectedRegion region = platform.getRegionContainer().get(BukkitAdapter.adapt(world)).getRegion(r);
	if (region == null)
		throw new StreamCorruptedException("Invalid region " + r + " in world " + world);
	this.region = region;
}
 
Example 30
Project: orion   File: Serializer.java    License: Apache License 2.0 5 votes vote down vote up
private static ObjectMapper getMapperOrThrows(final HttpContentType contentType) {
  switch (contentType) {
    case ORION:
      return jsonObjectMapper;
    case JSON:
      return jsonObjectMapper;
    case CBOR:
      return cborObjectMapper;
    default:
      throw new OrionException(OrionErrorCode.OBJECT_UNSUPPORTED_TYPE, new NotSerializableException());
  }
}
 
Example 31
Project: Tomcat8-Source-Read   File: StandardSession.java    License: MIT License 4 votes vote down vote up
/**
 * Write a serialized version of this session object to the specified
 * object output stream.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  The owning Manager will not be stored
 * in the serialized representation of this Session.  After calling
 * <code>readObject()</code>, you must set the associated Manager
 * explicitly.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  Any attribute that is not Serializable
 * will be unbound from the session, with appropriate actions if it
 * implements HttpSessionBindingListener.  If you do not want any such
 * attributes, be sure the <code>distributable</code> property of the
 * associated Manager is set to <code>true</code>.
 *
 * @param stream The output stream to write to
 *
 * @exception IOException if an input/output error occurs
 */
protected void doWriteObject(ObjectOutputStream stream) throws IOException {

    // Write the scalar instance variables (except Manager)
    stream.writeObject(Long.valueOf(creationTime));
    stream.writeObject(Long.valueOf(lastAccessedTime));
    stream.writeObject(Integer.valueOf(maxInactiveInterval));
    stream.writeObject(Boolean.valueOf(isNew));
    stream.writeObject(Boolean.valueOf(isValid));
    stream.writeObject(Long.valueOf(thisAccessedTime));
    stream.writeObject(id);
    if (manager.getContext().getLogger().isDebugEnabled())
        manager.getContext().getLogger().debug
            ("writeObject() storing session " + id);

    // Accumulate the names of serializable and non-serializable attributes
    String keys[] = keys();
    ArrayList<String> saveNames = new ArrayList<>();
    ArrayList<Object> saveValues = new ArrayList<>();
    for (int i = 0; i < keys.length; i++) {
        Object value = attributes.get(keys[i]);
        if (value == null) {
            continue;
        } else if (isAttributeDistributable(keys[i], value) && !exclude(keys[i], value)) {
            saveNames.add(keys[i]);
            saveValues.add(value);
        } else {
            removeAttributeInternal(keys[i], true);
        }
    }

    // Serialize the attribute count and the Serializable attributes
    int n = saveNames.size();
    stream.writeObject(Integer.valueOf(n));
    for (int i = 0; i < n; i++) {
        stream.writeObject(saveNames.get(i));
        try {
            stream.writeObject(saveValues.get(i));
            if (manager.getContext().getLogger().isDebugEnabled())
                manager.getContext().getLogger().debug(
                        "  storing attribute '" + saveNames.get(i) + "' with value '" + saveValues.get(i) + "'");
        } catch (NotSerializableException e) {
            manager.getContext().getLogger().warn(
                    sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
        }
    }

}
 
Example 32
Project: jdk8u-dev-jdk   File: PreferenceChangeEvent.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
* Throws NotSerializableException, since PreferenceChangeEvent objects
* are not intended to be serializable.
*/
private void readObject(java.io.ObjectInputStream in)
                                          throws NotSerializableException {
    throw new NotSerializableException("Not serializable.");
}
 
Example 33
Project: Skript   File: Fields.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public void setFields(final Object o, final Yggdrasil y) throws StreamCorruptedException, NotSerializableException {
	assert yggdrasil == y;
	setFields(o);
}
 
Example 34
Project: hottub   File: PSVIDocumentImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void writeObject(ObjectOutputStream out)
throws IOException {
throw new NotSerializableException(getClass().getName());
}
 
Example 35
Project: hottub   File: PSVIAttrNSImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void writeObject(ObjectOutputStream out)
    throws IOException {
    throw new NotSerializableException(getClass().getName());
}
 
Example 36
Project: Skript   File: PreciousStonesHook.java    License: GNU General Public License v3.0 4 votes vote down vote up
@Override
public Fields serialize() throws NotSerializableException {
    return new Fields(this);
}
 
Example 37
Project: jdk8u60   File: UnwarrantedOptimismException.java    License: GNU General Public License v2.0 4 votes vote down vote up
private void writeObject(final ObjectOutputStream out) throws NotSerializableException {
    throw new NotSerializableException(getClass().getName());
}
 
Example 38
Project: Tomcat7.0.67   File: StandardSession.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Write a serialized version of this session object to the specified
 * object output stream.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  The owning Manager will not be stored
 * in the serialized representation of this Session.  After calling
 * <code>readObject()</code>, you must set the associated Manager
 * explicitly.
 * <p>
 * <b>IMPLEMENTATION NOTE</b>:  Any attribute that is not Serializable
 * will be unbound from the session, with appropriate actions if it
 * implements HttpSessionBindingListener.  If you do not want any such
 * attributes, be sure the <code>distributable</code> property of the
 * associated Manager is set to <code>true</code>.
 *
 * @param stream The output stream to write to
 *
 * @exception IOException if an input/output error occurs
 */
protected void writeObject(ObjectOutputStream stream) throws IOException {

    // Write the scalar instance variables (except Manager)
    stream.writeObject(Long.valueOf(creationTime));
    stream.writeObject(Long.valueOf(lastAccessedTime));
    stream.writeObject(Integer.valueOf(maxInactiveInterval));
    stream.writeObject(Boolean.valueOf(isNew));
    stream.writeObject(Boolean.valueOf(isValid));
    stream.writeObject(Long.valueOf(thisAccessedTime));
    stream.writeObject(id);
    if (manager.getContainer().getLogger().isDebugEnabled())
        manager.getContainer().getLogger().debug
            ("writeObject() storing session " + id);

    // Accumulate the names of serializable and non-serializable attributes
    String keys[] = keys();
    ArrayList<String> saveNames = new ArrayList<String>();
    ArrayList<Object> saveValues = new ArrayList<Object>();
    for (int i = 0; i < keys.length; i++) {
        Object value = attributes.get(keys[i]);
        if (value == null)
            continue;
        else if ( (value instanceof Serializable)
                && (!exclude(keys[i]) )) {
            saveNames.add(keys[i]);
            saveValues.add(value);
        } else {
            removeAttributeInternal(keys[i], true);
        }
    }

    // Serialize the attribute count and the Serializable attributes
    int n = saveNames.size();
    stream.writeObject(Integer.valueOf(n));
    for (int i = 0; i < n; i++) {
        stream.writeObject(saveNames.get(i));
        try {
            stream.writeObject(saveValues.get(i));
            if (manager.getContainer().getLogger().isDebugEnabled())
                manager.getContainer().getLogger().debug(
                        "  storing attribute '" + saveNames.get(i) + "' with value '" + saveValues.get(i) + "'");
        } catch (NotSerializableException e) {
            manager.getContainer().getLogger().warn(
                    sm.getString("standardSession.notSerializable", saveNames.get(i), id), e);
        }
    }

}
 
Example 39
Project: jdk1.8-source-analysis   File: NodeChangeEvent.java    License: Apache License 2.0 4 votes vote down vote up
/**
* Throws NotSerializableException, since NodeChangeEvent objects are not
* intended to be serializable.
*/
private void writeObject(java.io.ObjectOutputStream out)
                                          throws NotSerializableException {
    throw new NotSerializableException("Not serializable.");
}
 
Example 40
Project: brooklyn-server   File: BrooklynJacksonSerializerTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testNonSerializableInMapIsShownInMap() throws Exception {
    Map<?,?> result = checkSerializesAs(MutableMap.of("x", new SelfRefNonSerializableClass()), Map.class);
    Assert.assertEquals( ((Map<?,?>)result.get("x")).get("errorType"), NotSerializableException.class.getName() );
}