java.io.NotSerializableException Java Examples

The following examples show how to use java.io.NotSerializableException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JGroupsServerLocatorSchema.java    From activemq-artemis with 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
Source File: CacheEntryProcessorNonSerializableTest.java    From ignite with 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
Source File: DistributionChannel.java    From gemfirexd-oss with 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 #4
Source File: PdxSerializableJUnitTest.java    From gemfirexd-oss with 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 #5
Source File: StdJDBCDelegate.java    From AsuraFramework with 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 #6
Source File: FunctionStreamingReplyMessage.java    From gemfirexd-oss with 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 #7
Source File: ClientNotifForwarder.java    From jdk8u-jdk with 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 #8
Source File: InvalidPropertiesFormatException.java    From Bytecoder with 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 #9
Source File: CertPath.java    From jdk8u_jdk with 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 #10
Source File: CertPath.java    From dragonwell8_jdk with 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
Source File: CertPath.java    From jdk8u-dev-jdk with 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 #12
Source File: PinLastArguments.java    From openjdk-jdk8u with 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
Source File: ClientNotifForwarder.java    From jdk1.8-source-analysis with 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
Source File: SerializedLambdaTest.java    From hottub with 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 #15
Source File: ProxyInvocationHandler.java    From beam with 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 #16
Source File: CertPath.java    From jdk8u-jdk with 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
Source File: TestIssueRepository.java    From quickperf with 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 #18
Source File: CClipboard.java    From dragonwell8_jdk with 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
Source File: PinLastArguments.java    From dragonwell8_jdk with 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
Source File: Serializer.java    From orion with 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 #21
Source File: DefaultListableBeanFactory.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
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
Source File: EndpointPermission.java    From knopflerfish.org with 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
Source File: CClipboard.java    From jdk8u-jdk with 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
Source File: CertPath.java    From j2objc with 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
Source File: CapabilityPermission.java    From concierge with 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
Source File: PinLastArguments.java    From TencentKona-8 with 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
Source File: AbstractEntityManagerFactoryBean.java    From java-technology-stack with 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
Source File: PinLastArguments.java    From jdk8u-jdk with 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
Source File: WorldGuardHook.java    From Skript with 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
Source File: CertPath.java    From hottub with 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;
    }
}