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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:34:26+00:00 2026-05-11T13:34:26+00:00

The recommended way to use the EventActionDispatcher is as follows (per the API docs

  • 0

The recommended way to use the EventActionDispatcher is as follows (per the API docs @ http://struts.apache.org/1.2.9/api/org/apache/struts/actions/EventActionDispatcher.html )

   public class MyCustomAction extends Action {         protected ActionDispatcher dispatcher = new EventActionDispatcher(this);         public ActionForward execute(ActionMapping mapping,                                     ActionForm form,                                     HttpServletRequest request,                                     HttpServletResponse response)                            throws Exception {            return dispatcher.execute(mapping, form, request, response);        }    } 

Does doing this publish the reference to ‘this’ before the constructor exits? What are the rules governing field assignments outside of methods.

Thanks in advance.

Sincerely, LES

  • 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. 2026-05-11T13:34:26+00:00Added an answer on May 11, 2026 at 1:34 pm

    That took 3 people a week to track down once… ‘this’ can be null if the EventActionDispatcher starts a thread or does anything with a thread that causes the ‘this’ to be used.

    NEVER pass ‘this’ before the constructor has completed or you run the risk of ‘this’ being null in the case of threading.

    What I do is add an ‘init()’ method to my classes that need to do things like that and call it after I create the object.

    There are also other subtleties, such as this example:

    public abstract class Foo {     protected Foo()     {         car();     }      public abstract void car(); }  public class Bar      extends Foo {     private final String value;      public Bar(final String str)     {         value = str;     }      public void car()     {         // this line will crash because value is null         System.out.println(value.charAt(0));     } }  public class Main {     public static void main(final String[] argv)     {         final Foo foo;          foo = new Bar('Hello');     } } 

    The safest thing to do is:

    • never use ‘this’ before the constructor has returned
    • never call any of the classes own non-static methods from a constructor unless the class is final.

    You can can call final methods, but you have to be sure that they do not call overrideable methods… and that can mean things break down the road… so safer not to do it.

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

Sidebar

Ask A Question

Stats

  • Questions 78k
  • Answers 78k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer It's a perfectly legitimate solution for some designs. Say you… May 11, 2026 at 3:40 pm
  • added an answer have you tried? $.jmsajax({ ... data: { uname: $uname },… May 11, 2026 at 3:40 pm
  • added an answer It's the primary key (CustomerID) of the First Customer entry… May 11, 2026 at 3:40 pm

Related Questions

What is the best way to upload a file to a Document Library on
Similar to the known memory leak issue regarding creating and destroying an instance of
I'd like to use Visual Studio 2008 IDE for editing my local database schema
I have code that reads the Windows Event Log. It uses OpenEventLog, ReadEventLog and

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.