Uploaded image for project: 'Wink'
  1. Wink
  2. WINK-426

wink-osgi is broken

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • None
    • None
    • OSGi
    • None

    Description

      I've been looking at WinkRequestProcessor code for a bug that I've experienced. There is a very strange method inside:

      	protected void activate(ComponentContext context) {
      		// hint from https://amdatu.atlassian.net/wiki/display/AMDATU/OSGiification
      		// dummy RuntimeDelegate
      		RuntimeDelegate.setInstance(new DummyRuntimeDelegate());
      		RuntimeDelegate.setInstance(new RuntimeDelegateImpl());	
      		init();
      	}
      

      Since I've got some NPEs when doing requests, I've been particularly interested in DummyRuntimeDelegate, which return only nulls.

      Removing the class didn't helped at all. It actually prevented the bundle from being initialized.

      Anyway, the problem seemed to be org.apache.wink.common.internal.providers.header.EntityTagMatchHeaderDelegate. It has the following code:

          private final static RuntimeDelegate           delegate                   =
                                                                                        RuntimeDelegate
                                                                                            .getInstance();
          private static final HeaderDelegate<EntityTag> ENTITY_TAG_HEADER_DELEGATE =
                                                                                        delegate
                                                                                            .createHeaderDelegate(EntityTag.class);
      

      So during the initialization of RuntimeDelegateImpl, this class is accessed and it's static fields are initialized. But during initialization RuntimeDelegate.getInstance() will return DummyDelegate, and then ENTITY_TAG_HEADER_DELEGATE will become null (Dummy delegate always returns nulls).

      So in the fromString method, the line below will fail with NPE:

      ifMatchHeader.addETag(ENTITY_TAG_HEADER_DELEGATE.fromString(token));
      

      I've modified a little bit the code of fromString() to look like that and works perfectly:

      HeaderDelegate<EntityTag> ENTITY_TAG_HEADER_DELEGATE = RuntimeDelegate.getInstance().createHeaderDelegate(EntityTag.class);
      ifMatchHeader.addETag(ENTITY_TAG_HEADER_DELEGATE.fromString(token));
      

      Fixing those static fields in EntityTagMatchHeaderDelegate class only, makes DummyRuntimeDelegate obsolete.

      Attachments

        Activity

          People

            Unassigned Unassigned
            v_valchev Valentin Valchev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated: