Findbugs not excluding methods in our java application - java

I have added the following in the findbugs exclude.xml file
<Match>
<Class name="com.ebay.kernel.service.invocation.SvcInvocationConfig" />
<Method name="getConnectionConfig" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>
The code that needs to be ignored
public ConnectionConfig getConnectionConfig() {
return m_connectionConfig;
}
because Findbugs reports that
m_connectionConfig suffers from (inconsistent synchronization) BUG - IS2_INCONSISTENT_SYNC
But for some reason my findbugs are not getting ignored.
and when I do following -
<Match>
<Class name="com.ebay.kernel.service.invocation.SvcInvocationConfig" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>
The findbugs is getting ignored for the entire class but as soon as I introduce
<Method name="getConnectionConfig">
tag in between, findbugs stops getting ignored for that method.
Can someone help me figure out why?

The IS2_INCONSISTENT_SYNC warning is issued on a data member (field), according to its usages by various methods, constructors, static blocks, etc. and not on the method itself, so you can't ignore it with a <Method> element.
Instead, you could use a <Field> element:
<Match>
<Class name="com.ebay.kernel.service.invocation.SvcInvocationConfig" />
<Field name="m_connectionConfig" />
<Bug pattern="IS2_INCONSISTENT_SYNC" />
</Match>

Related

obfuscating with allatori obfuscates too much

I have the following config.xml file
<config>
<input>
<jar in="FVCellsPlugin-3.3.1-jcg.jar" out="obf-FVCellsPlugin-3.3.1-jcg.jar"/>
</input>
<keep-names>
<class template="class io.github.freakyville.fvcells.main.Main"/>
<class template="class regex:(?!io\.github\.freakyville).*\..*">
<field template="*"/>
<field template="static *"/>
<field template="public static *"/>
<method template="private+ *(**)"/>
<method template="private+ static *(**)"/>
</class>
<class template="private+ class regex:io\.github\.freakyville\.utilsupdated\..*"/>
</keep-names>
<property name="log-file" value="log.xml"/>
<property name="line-numbers" value="keep"/>
</config>
So I tried a few things without it working, all my code that i want obfuscated is in the package(or sub packages) io.github.freakyville(except io.github.freakyville.utilsupdated).
when the plugin is enabled I get an error java.lang.NoSuchMethodError: com.mongodb.client.model.geojson.c.iiiiiI(Ljava/lang/String;)Ljava/lang/String; which shows that it is obfuscating the class inside com.mongodb.client.model.geojson, When looking inside the jar I can see that it has obfuscated the geojson.c class https://gyazo.com/45c17157d5d7a213f14a9ecc2c12b4f6 which to me doesn't make sence as my regex (?!io\.github\.freakyville).*\..* should match that package/class path and then keep the package/class right?
Ah I figured it out, I missed the tag in the documentation(which ignores the classes matched in the obfuscating process). Adding my class templates to that and now it works

How to make VS Code organize Java imports like IntelliJ

I'm using VS Code for Java development and working with other developers who use IntelliJ. I'd like to use the Organize Imports command (Shift+Alt+O) to clean up my imports, but I don't want to fight over import order with every commit. So I'd like to configure VS Code to organize the imports in the same order as IntelliJ's default. Does anybody have a configuration that would do this?
If this is not possible, is there a workspace configuration I can apply to both VS Code and IntelliJ so that the two IDEs will agree, even if they aren't agreeing on IntelliJ's default?
We were able to get it the almost identical with the following config tweaks.
VS Code:
{
"java.completion.importOrder": [
"",
"javax",
"java",
"#"
]
}
IntelliJ
The only difference from the IntelliJ default is a new line between import javax... and import java....
It's possible to get VS Code and IntelliJ to agree on a standard format, as long as that standard format:
Puts static imports at the top*
Separates all specific sections with empty lines
Puts everything not in its own specific section in a catch-all section at the end*
Never uses wildcard imports
Not actually true; static imports can be positioned in VS Code with '#', and everything else can be position in VS Code with ''.
IntelliJ's default settings don't work for this, but it is flexible enough to be reconfigured. Here are the files to add to a project to make just that project set up consistent rules for both IDEs (make sure they are not excluded in .gitignore).
Rule: The following groups separated by empty lines: Static imports, java.*, javax.*, everything else.
.vscode/settings.json:
{
"java.completion.importOrder": ["java", "javax"],
}
.idea/codeStyles/codeStyleConfig.xml:
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
</state>
</component>
.idea/codeStyles/Project.xml
<component name="ProjectCodeStyleConfiguration">
<code_scheme name="Project" version="173">
<JavaCodeStyleSettings>
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
<option name="IMPORT_LAYOUT_TABLE">
<value>
<package name="" withSubpackages="true" static="true" />
<emptyLine />
<package name="java" withSubpackages="true" static="false" />
<emptyLine />
<package name="javax" withSubpackages="true" static="false" />
<emptyLine />
<package name="" withSubpackages="true" static="false" />
</value>
</option>
</JavaCodeStyleSettings>
</code_scheme>
</component>

Findbugs report without bug description

Findbugs is generating the following report:
<BugCollection version="3.0.1" threshold="medium" effort="min">
<file classname="com.example.MyClass"/>
<Error/>
<Project>
<SrcDir>
/Users/user/Developer/Service/src/main/java
</SrcDir>
<SrcDir>
/Users/user/Developer/Service/src/test/java
</SrcDir>
</Project>
</BugCollection>
I already added this to the exclude filter file:
<FindBugsFilter>
<Match>
<Class name="com.example.MyClass" />
</Match>
</FindBugsFilter>
I can't make findBugs succeed in my project. Someone knows why findBugs is saying that this class has a bug?
Unfortunately I can't post the code of the class. The class is very simple, is just a validation class.

How to add Annotations elements in metadata generated by Apache Olingo V2.0?

I have developed Odata service for a system entity which generates a metadata but however I cant figure out how to add Annotations element to it. Sample Metadata generated is as follows :-
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:sap="http://www.sap.com/Protocols/SAPData" Version="1.0">
<edmx:DataServices xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"
m:DataServiceVersion="1.0">
<Schema xmlns="http://schemas.microsoft.com/ado/2008/09/edm" Namespace="myNamespace" sap:schema-version="1">
<EntityType Name="System">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="name" Type="Edm.String" sap:label="System Name" sap:creatable="false"
sap:updatable="false" sap:sortable="false" sap:required-in-filter="true"/>
<Property Name="description" Type="Edm.String" />
<Property Name="status" Type="Edm.String" />
<Property Name="type" Type="Edm.String" />
</EntityType>
<EntityContainer Name="ODataEntityContainer" m:IsDefaultEntityContainer="true">
<EntitySet Name="Systems" EntityType="myNamespace.System" />
<FunctionImport Name="NumberOfSystems" ReturnType="Collection(myNamespace.System)"
m:HttpMethod="GET" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
I need to add following elements to above metatada
<Annotations Target="myNamespace.System"
xmlns="http://docs.oasis-open.org/odata/ns/edm">
<Annotation Term="com.sap.vocabularies.UI.v1.LineItem">
<Collection>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="name" />
</Record>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="description"/>
</Record>
<Record Type="com.sap.vocabularies.UI.v1.DataField">
<PropertyValue Property="Value" Path="status" />
</Record>
</Collection>
</Annotation>
</Annotations>
I came across the org.apache.olingo.commons.api.edm.provider.annotation package but cant find any suitable API. Please let me know how should I proceed.
Thanks in advance.
The annotations you would like to use have been introduced with OData V3 which is why they are not directly supported with the Olingo V2 library.
You can use the EdmProvider AnnotationElement and AnnotationAttribute classes to mimic this behaviour though. For example You can create a AnnotationElement with the name "Annotations" this element will then have the "AnnotationAttribute" Target=SomeString. Since an "AnnotationElement" can have child elements you can put your Collection element there. Namespaces are also handled with "AnnotationAttributes".
You can only attach the annotation to Edm elements which are derived from the EdmAnnotatable interface. So this is a difference to V3.
This is currently the only way to get this behaviour with Olingo V2.

Continue TestNG test after failed method

I have a TestNG suite set up to perform a number of selenium tests that. The suite has a number of tests in it, which each have a number of classes, which each have one or two test methods. I am currently experiencing behavior where the whole test ( tag) will stop if one test method fails (i.e. results will look like: pass, pass, pass, fail, skip, skip, skip, skip, skip, skip).
Is there a way for me to set up my tests so that a single method failure won't prevent the others from running? My test methods are mostly independent from one another, and the classes definitely are, but all of the classes are sharing a WebDriver instance.
Here is an example of one of my tags in my XML file. There are several other test cases with the same class list but different parameters. unfortunately I cannot show my actual code as it contains privileged information.
<test name="OS_X_Mavericks_Firefox_27_Test">
<parameter name="browser" value="Firefox" />
<parameter name="browser_version" value="27.0" />
<parameter name="os" value="OS X" />
<parameter name="os_version" value="Mavericks" />
<parameter name="resolution" value="1920x1080" />
<classes>
<class name="SuperTestClass" />
<class name="testClass1" />
<class name="testClass2" />
<class name="testClass3" />
<class name="testClass4" />
<class name="testClass5" />
<class name="testClasa6" />
<class name="testClass7" />
<class name="testClass8" />
<class name="testClass9" />
</classes>
</test>
As it turns out, the problem was with my inheritance structure. I had an #AfterClass method in SuperTestClass, which all of the other test classes inherited from. So, when one test failed in the #AfterClass method, all subsequent tests that inherited from SuperTestClass (all of the tests) failed.

Categories