Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1014035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:11:38+00:00 2026-05-16T10:11:38+00:00

I’m trying to send objects from bundles over a dedicated communication bundle to an

  • 0

I’m trying to send objects from bundles over a dedicated communication bundle to an other framework. For communication I use Java standard serialization (with ObjectStreams) over TCP/IP.

Communication flow is the following: A sender-bundle will pass serializable objects to a transmit-sender which will serialize the objects and send them via TCP/IP to a transmit-receiver. The receiver will then deserialize the received objects and pass them to the receiver-bundle.

As the OSGi classloading architecture is different than the native one, I have to make a littel hack with the classloader: As I assume that the receiver-bundle should know the classes which he receives (= has them imported or otherwise accessible by its classloader), I use the classloader of the receiver instead of the transmit-receiver to load the class. (Via the Bundle.loadClass(..) method).
This works fine for custom classes, however, this does not work for arrays of custom types.
(Which are not known to the transmit-receiver classloader but to the receiver-bundle.)

Edit: ObjectInputStream.readObject(…) throws an ClassNotFoundException, if It tries to deserialize an array. (I assume that this exception origins in the Bundle.loadClass(…) method of the receiver-bundle. )

It does work with java.util.List or other Serializable classes. It also works for custom types which contains fields of other custom types as long as they are not arrays.

So the question is: Is there any difference in the way arrays are de/serialized? Or are they loaded differently?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:11:38+00:00Added an answer on May 16, 2026 at 10:11 am

    I suspect you’ve implemented ObjectInputStream.resolveClass using Bundle.loadClass directly. If so, you’re hitting this problem: https://bugs.java.com/bugdatabase/view_bug?bug_id=6516909

    Basically, ClassLoader.loadClass was never intended to be used for array classes. The easiest way to load array classes is to use Class.forName. Unfortunately, there is no easy way to do that with OSGi. You’ll either need a Bundle ClassLoader proxy, or you’ll need to do some pre-processing on the class names to ensure that you don’t pass arrays directly to loadClass:

    public static Class<?> bundleClassForName(Bundle bundle, String name) throws ClassNotFoundException {
        int length = name.length();
        if (length > 0 && name.charAt(0) == '[') {
            int pos = 1;
            while (pos < length && name.charAt(pos) == '[') {
                pos++;
            }
    
            if (pos < name.length()) {
                if (name.charAt(pos) != 'L') {
                    return Class.forName(name);
                }
    
                if (name.charAt(length - 1) == ';') {
                    String componentName = name.substring(pos + 1, length - 1);
                    Class<?> klass = bundle.loadClass(componentName);
                    ClassLoader loader = klass.getClassLoader();
                    return Class.forName(name, false, loader);
                }
            }
        }
    
        return bundle.loadClass(name);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.