We found a bug in old code which could be easily found if there would be a warning,
The issue was that inner class member was used but not assigned or initialized. Sample code minimized. Problem is that url is always null.
public class Main {
public class Sender {
private String url;
public Sender() {
}
public void send() {
OtherClass.send(url);
}
}
}
In intellij it warns about variable never assigned. In eclipse I didn't find such warning.
The code is more complex and adding a warning at any level will reduce time to find similar bugs.
Is it possible in eclipse to warn in some way if variable is used before assigned/initialized ?
You can use SpotBugs(successor of findbugs) eclipse plugin. Right click on project Spotbugs->find bugs this will find these types of bugs.
I suggest also installing sonarlint plugin which has good static analysis capabilities.
https://marketplace.eclipse.org/content/spotbugs-eclipse-plugin
https://marketplace.eclipse.org/content/sonarlint
Related
First, all my action listeners call a private method in my class. They are in the initComponents method that is not static, and so are the private method called by the action listeners.
The project was on Java 1.5 and moved to Java 1.8. SonarLint didn't like those statements :
someButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
doSomeAction(evt);
}
});
At first, SonarLint propose to change those assignment using lambdas (Squid:S1604).
I changed those with:
someButton.addActionListener(e -> doSomeAction(e));
Then the strange Squid:S1612 occured: it propose to use method references instead. Here is what I did:
someButton.addActionListener(ClassName::doSomeAction);
Then Eclipse Oxygen said that this is an error and won't compile The error message is:
Cannot make a static reference to the non-static method doSomeAction(ActionEvent) from the type ClassName
So the question is: can I really use method reference or should I just stick with lambda?
Please note that I've searched for this particular question & found couple of them but none of them had scenario related to cucumber integration.
I've a test runner class extending AbstractTestNGCucumberTests.
I've also installed Eclipse TestNG plugin as well 6.12
Also adding entry under TestNG under Run Configuration, didn't help to solve the issue.
Mac + Eclipse 4.7.0
#CucumberOptions(features={"src/test/resources/WunderlistAndroid.feature"}, strict = false, format = { "pretty","json:target/cucumber.json" }, tags = { "~#ignore" })
public class WLSignIn extends AbstractTestNGCucumberTests{
#BeforeClass
public void launchAppiumServer(){
//code doing desired action
}
#AfterClass
public void killAppiumServer(){
//code doing desired action
}
}
The problem is due to the fact that the eclipse TestNG plugin doesn't see any #Test methods in your class. I believe the plugin is contextual in nature and hence shows the Run As > TestNG Test only when it sees atleast one #Test method in your test class. Since the #Test method resides in your base class, the plugin doesnt see that and hence you don't see it.
To get past this, you can perhaps add a dummy test method such as the one below and that should bring back the Run as > TestNG test option.
#Test(enabled=false)
public void dummyTestMethod() {}
On a side note: You might want to file this as an issue in the TestNG project and see if its worth getting fixed.
Details that can be used for the bug :
If the base class resides within a jar (and has one or more #Test annotated test methods) then the eclipse testng plugin doesn't see the child class (WLSignIn) the first time. But after one adds a disabled #Test method to the child class (WLSignIn) the option shows up. This happens irrespective of whether the child class extends from another class in the same project or from another class which resides in a jar (in your case cucumber.api.testng.AbstractTestNGCucumberTests)
We have implemented a SonarQube-plugin with an extension that implements Decorator and deployed it to extensions/plugins.
Unfortunately, when triggering the sonar-analysis, the extension implementation is not called. Is there anything more that needs to be configured?
The implementation looks as simple as this:
public class MyPlugin extends SonarPlugin {
#Override
public List getExtensions() {
return Arrays.asList(MyExt.class);
}
}
#DependsUpon(DecoratorBarriers.ISSUES_TRACKED)
public class MyExt implements Decorator, BatchComponent {
#Override
public void decorate(Resource resource, DecoratorContext decoratorContext) {
Project project = decoratorContext.getProject();
Measure measure = new Measure();
measure.setData("abc");
decoratorContext.saveMeasure(measure);
}
#Override
public boolean shouldExecuteOnProject(Project project) {
return true;
}
}
If you're using SQ 5.2, Decorator does not work anymore. You have to move to the MeasureComputer interface instead.
The API is really unclear about this, and the #Deprecated annotation is misused IMHO (usually you first deprecate code, keep it working until it does not work anymore, then you just delete it... you don't deprecate code in order to inform people that it's not usable anymore...)
I guess that somebody at SonarSource forgot what code deprecation is about...
While a deprecated software feature remains in the software, its use may raise warning messages recommending alternative practices; deprecated status may also indicate the feature will be removed in the future. Features are deprecated rather than immediately removed, to provide backward compatibility and give programmers time to bring affected code into compliance with the new standard.
I am developing a couple of custom widgets that I would like to be able to use with UiBinder. Unfortunately I keep wasting my life away with chasing down the following error:
No class matching "..." in urn:import:...
This seems to be the catch-all exception that is thrown any time there is any error in the class that prevents the GWT compiler from processing it. This includes anything in the class's entire dependency tree.
To save myself and anyone of you who is running into the same issue some time and pain, let's compile a list here of the most unexpected and hard to find causes for this. I'll start with my latest one, which has made me decide to post this here.
I was using a CellList thusly:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
note the Java 7 style <> on the CellList. Despite my IDE's protestations to the contrary, it turns out you DO need to explicitly say CellList< String> in that new call, or it wont compile and all you get is the above mentioned error. Thanks by the way, the existance of this question prompted me to scrutinise my code and probably saved me a couple of hours! This fixed it:
private static RelationshipViewerUiBinder uiBinder = GWT.create(RelationshipViewerUiBinder.class);
#UiField(provided=true)
CellList<String> prioritisedDisplay;
public RelationshipViewer() {
prioritisedDisplay = new CellList<String>(new TextCell());
initWidget(uiBinder.createAndBindUi(this));
}
I had written a component that used the GWT JSON functionality, but hadn't imported com.google.gwt.json.JSON into the module.
Thanks to your message here, this was only 2 hours down the drain...
I wrote a helper-class that this widget uses somewhere deep inside its dependency tree.
For this helper-class, I told Eclipse to auto-generate the hashCode() and equals(...) functions. The class contained a field of type double, for which Eclipse generates code that uses Double.doubleToLongBits().
Turns out GWT does not implement this method on its version of Double. But of course, neither does Eclipse detect this as a possible compile-error, nor does it cause any issues in Dev Mode if I use the widget inside the GWT-App's Java code rather than inside UiBinder.
3 hours down the drain... Great... Yay for helpful error messages.
UPDATE:
As of GWT 2.5.0 (RC1) GWT now supports Double.doubleToLongBits() rendering this particular error obsolete, but the general error mechanism of a missing JRE emulation remains and will probably manifest itself in a similarly unhelpful way.
I was trying to use a GwtQuery DragAndDropCellTree in a UiBinder .ui.xml, which was impossible as DragAndDropCellTree has no zero-arg constructor.
See more details
I'm in a generic method, debugging, but i get no information about variables, can't execute statements using ctrl-shift-i, eclipse tells the that the method ... isn't available on the type T.
I can't believe it's meant to (not) work like this ...
[edit]
I'm using the eclipse that's part of RAD 7.5.4
[another edit]
Here's some code but I doubt you'll get any info from this
public abstract class GenericGroupController<T extends Group> {
...
public String addUser(final Model model, final Long id, final WebRequest request) {
T group = groupManager.loadGroup(id);
...
// this method will fail if i highlight and click ctr-shift-i
// but it will work otherwise (actually so will the method above
// because that's generic as well)
Long groupId = group.getId();
...
return getAddUserView();
}
}
If you are able to debug, as in see a stack trace, you can always see the variables in the variables window if not in the code. A lot of places where the code isn't available you can do the same. It isn't nice, but, it gets the job done.