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 4028808
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:15:59+00:00 2026-05-20T11:15:59+00:00

While writing a simple remoting test I’ve come up against a suprising situation involving

  • 0

While writing a simple remoting test I’ve come up against a suprising situation involving DBI (double braces initialization) which I’ve been unable to fully understand, so I would ask for some assistance.

Consider the following code:

public class RemotingTest {

@Autowired
private RemotingTestController remotingTestController;

//DBI
List<SomeBean> mockList = new ArrayList<SomeBean>(){{
        add(MockFactoryBean.getMockBean());
}};

@Test
public void testRemoting() {
    try {
        // controller code is not relevant - it simply passes this list 
        // via Spring's HttpInvokerProxyFactoryBean to a session facade which then 
        // passes the list further down the SOA stack...
        String result = remotingTestController.createBeanRemotely(mockList); 
        log.debug(result);
    } catch (Exception e) {
        fail();
        e.printStackTrace();
    }
}

}

This code bombs in run-time with the following error which makes no sense to me:

java.io.NotSerializableException: org.stackoverflow.RemotingIntegrationTest
  at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)
  at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)
  <<stacktrace snipped>>
  at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.executeRequest(HttpInvokerClientInterceptor.java:174)
  at org.springframework.remoting.httpinvoker.HttpInvokerClientInterceptor.invoke(HttpInvokerClientInterceptor.java:142)
... 33 more

If, however I am to simply omit DBI and use vanilla-style pattern to add an element to a list, as in:

    public class RemotingTest {

@Autowired
private RemotingTestController remotingTestController;

List<SomeBean> mockList = new ArrayList<SomeBean>();

@Test
public void testRemoting() {
    mockList.add(MockFactoryBean.getEcopStatusMock());

    try {
    //this block stays the same
        } catch (Exception e) {
        //.....
    }
}

}

everything works properly and serializes without a hitch. I’ve even tried to make the test Serializable (shudders) but that yielded exactly nothing, as the test died with a even more interesting error – that the HttpInvokerServiceExporter should implement Serializable 🙂

The question is – why is that so? Researching DBI a bit led me to believe that by adding an element to a list this way actually made two objects – the expected ArrayList<T>() and a new subclassed ArrayList<T>() object which contained the added element; this somehow confuses Spring’s Remoting and dies a gruesome death with a NotSerializableException.

I am not sure, however, if that is what happens behind the scene, so any help in explaining this would be appreciated.

The environment uses the following:

  • Spring 3.0.4
  • JDK 1.6.0 Update 23
  • IceFaces 1.8.2
  • 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-20T11:15:59+00:00Added an answer on May 20, 2026 at 11:15 am

    This is happening because the double-brace initialization syntax creates an anonymous subclass of ArrayList, and like all anonymous classes, it contains an implicit reference to their parent object (in this case, your test).

    In order to be serializable, the parent object (i.e. your test) would also have to be serializable. This is obviously not what you want here. You’ll just have to avoid that syntax, convenient thought it is.

    An equally convenient alternative for lists is:

    List<SomeBean> mockList = Arrays.asList(
        bean1, bean2, bean3
    );
    

    The DBI syntax is only really compelling when building Maps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While writing a file using ofstream, how do I know when the file's size
while writing a custom attribute in C# i was wondering if there are any
I got this doubt while writing some code. Is 'bool' a basic datatype defined
I'm engaged in writing a product using LinqToSql for data-access. While we're rapidly developing,
I find myself writing code that looks like this a lot: set<int> affected_items; while
OK, so instead of writing a whole bunch of access control specs, and duplicating
I am doing some research on Unicode for a white-paper I am writing. Does
While the C# spec does include a pre-processor and basic directives (#define, #if, etc),
While going through university and from following the development of SO, I've heard a
While I've seen rare cases where private inheritance was needed, I've never encountered a

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.