Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Scout » Question about Activator template in SDK
Question about Activator template in SDK [message #1464429] Fri, 07 November 2014 14:48 Go to next message
Patrick Tournet is currently offline Patrick TournetFriend
Messages: 17
Registered: July 2009
Location: Aix-en-Provence, FRANCE
Junior Member
Hi,

As I'm configuring my project and the development pipeline, I've set up a Sonar server and an analysis of the bare generated Scout plugins triggered several warnings a lot of which being field names not matching the regular expression '^[a-z][a-zA-Z0-9]*$'.

But 2 of them were flagged as critical... I've tracked the source to being in the org.eclipse.scout.sdk.rap/templates/client.mobile/src/Activator.java file :

public class Activator implements BundleActivator {
  private static BundleContext context;

  public static BundleContext getContext() {
    return context;
  }

  @Override
  public void start(BundleContext bundleContext) throws Exception {
    Activator.context = bundleContext;
  }

  @Override
  public void stop(BundleContext bundleContext) throws Exception {
    Activator.context = null;
  }
}


As you can see, there are 2 instance methods that are modifying a static field... Is there any reason for such a behaviour that can result in highly unpredictable results or is it fixable (by removing the static qualifier from the field for instance) ?


I can do anything and I can do it better than anyone. Be as I am : be the best ! Wink
Re: Question about Activator template in SDK [message #1467710 is a reply to message #1464429] Mon, 10 November 2014 08:39 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Patrick TOURNET wrote on Fri, 07 November 2014 15:48
But 2 of them were flagged as critical...


It seems to me, that is is a standard pattern for Activator classes.

If you create a new "Plug-in project" and you select "Generate an activator, a java class that controls the plug-ins' life cycle" in the second step, you end up with a class like this:

import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;

public class Activator implements BundleActivator {

	private static BundleContext context;

	static BundleContext getContext() {
		return context;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
	 */
	public void start(BundleContext bundleContext) throws Exception {
		Activator.context = bundleContext;
	}

	/*
	 * (non-Javadoc)
	 * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
	 */
	public void stop(BundleContext bundleContext) throws Exception {
		Activator.context = null;
	}

}


Same pattern as with the Eclipse Scout template... I agree with the SonarQube issue, this is not a recommended java pattern.

I my opinion you can mark those as false positive in SonarQube (for each Activator class).

Patrick TOURNET wrote on Fri, 07 November 2014 15:48
As I'm configuring my project and the development pipeline, I've set up a Sonar server and an analysis of the bare generated Scout plugins triggered several warnings a lot of which being field names not matching the regular expression '^[a-z][a-zA-Z0-9]*$'.


It is up to you to decide what your coding/naming convention will be.

Scout follows a pattern, where all member fields use the prefix: "m_".
If you want to keep this pattern in your scout application, you need to change the regular expression in the Sonar rule.


[Updated on: Mon, 10 November 2014 08:45]

Report message to a moderator

Re: Question about Activator template in SDK [message #1467784 is a reply to message #1467710] Mon, 10 November 2014 10:00 Go to previous messageGo to next message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Our Sonar complains about quite a few of the Scout generated patterns. Apart from the issues you mention the one that comes up most is the complaint about methods declaring "throws Exception" instead of the more specific errors being thrown.

We've just started adding the following comments at the end of those lines:

// NOSONAR - scout generated code

Of course, it would be nice if such code were no longer generated but for us this is a feasible workaround.
Re: Question about Activator template in SDK [message #1467888 is a reply to message #1467784] Mon, 10 November 2014 11:42 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
Urs Beeli wrote on Mon, 10 November 2014 11:00
Our Sonar complains about quite a few of the Scout generated patterns. Apart from the issues you mention the one that comes up most is the complaint about methods declaring "throws Exception" instead of the more specific errors being thrown.


Can you be more specific?

Are you speaking from the S00112 Rule: Generic exceptions Error, RuntimeException, Throwable and Exception should never be thrown?

I have started a discussion on their mailing list and they have fixed the bug SONARJAVA-443 by adding an exception when the method is overriden.

@Urs:
Where do you have the "throws Exception" Sonarqube issues?
Because the Scout Code itself uses ProcessingException or VetoException.


Re: Question about Activator template in SDK [message #1468384 is a reply to message #1467888] Mon, 10 November 2014 20:24 Go to previous messageGo to next message
Patrick Tournet is currently offline Patrick TournetFriend
Messages: 17
Registered: July 2009
Location: Aix-en-Provence, FRANCE
Junior Member
Thanks for your answers guys ! I've discovered some things I didn't know about Sonar (especially the NOSONAR keyword that I've already begun to use) and I'll dig a little deeper in its configuration (exclusion patterns, regular expressions, and so on...) ! Smile

I can do anything and I can do it better than anyone. Be as I am : be the best ! Wink
Re: Question about Activator template in SDK [message #1468405 is a reply to message #1468384] Mon, 10 November 2014 20:44 Go to previous messageGo to next message
Jeremie Bresson is currently offline Jeremie BressonFriend
Messages: 1252
Registered: October 2011
Senior Member
About exclusion patterns, check this article I have written: "Ignore Issues on Multiple Criteria" in SonarQube
Re: Question about Activator template in SDK [message #1470232 is a reply to message #1467888] Wed, 12 November 2014 07:19 Go to previous message
Urs Beeli is currently offline Urs BeeliFriend
Messages: 573
Registered: October 2012
Location: Bern, Switzerland
Senior Member
Jeremie Bresson wrote on Mon, 10 November 2014 12:42
Can you be more specific?

Are you speaking from the S00112 Rule: Generic exceptions Error, RuntimeException, Throwable and Exception should never be thrown?

@Urs:
Where do you have the "throws Exception" Sonarqube issues?
Because the Scout Code itself uses ProcessingException or VetoException.


It's labelled "Signature Declare Throws Exception (pmd:SignatureDeclareThrowsException)" but also states "This rule is deprecated, use S00112 instead. "

We've mainly seen this in the Activators but also in the ServerApplication and ClientApplication. Also, I think in some of the SyncJobs there is runVoid which even has a "throws Throwabl" signature (though I'm not 100% sure).

The thing at "Info" level is not a major issue (i.e. we don't bother NOSONARing them):
- on many (all?) generated inner classes:
Performance - Should be a static inner class (findbugs:SIC_INNER_SHOULD_BE_STATIC)
Performance - Could be refactored into a static inner class (findbugs:SIC_INNER_SHOULD_BE_STATIC_NEEDS_THIS)
Previous Topic:Accessing the HTML source code of the content of a BrowserField?
Next Topic:Swing PlannerField
Goto Forum:
  


Current Time: Thu Apr 25 04:56:54 GMT 2024

Powered by FUDForum. Page generated in 0.03271 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top