The call of the hashCode() method on File object , triggers this SonarQube issue :
Use the original value instead.
How to resolve? Any help please?
File file = ......
.... = Math.abs(file.hashCode());
Update: the SonarQube description of the issue is here
Can I just write : .... = Math.abs(file.hashCode()+1);
The cause of your problem is the fact that Integer.MIN returns itself when taking the absolute value. This issue is described here.
The solution depends on what you need the value for. Your suggested solution (Math.abs(file.hashCode() + 1)) won't work, because if the hashCode() function returns Integer.MAX then that plus 1 is still Integer.MIN, so the final result could still be negative.
If you really need a positive hash of the file, you could do something like this:
final int hash = file.hashCode() == Integer.MIN ? Integer.MAX : Math.abs(file.hashCode());
Related
To sign data, I am using signserver open-source code. I was exploring a legacy code where
it gives error at this place:
Module.getPKCS11Module().C_FindObjectsInit(session.getSessionHandle(), attributes,true);
where the Module class is from iaikpkcs11Wrapper.jar (package: iaik.pkcs.pkcs11)
As I navigate further, PKCS11 interface has this method void C_FindObjectsInit(long var1, CK_ATTRIBUTE[] var3, boolean var4) mentioned above.
Moreover, the attributes param is constructed like below:
CK_ATTRIBUTE[] attributes = new CK_ATTRIBUTEKeyStoreContainerBase[2];
attributes[0] = new CK_ATTRIBUTE();
attributes[0].type = PKCS11Constants.CKA_CLASS;
attributes[0].pValue = new Long(PKCS11Constants.CKO_SECRET_KEY);
attributes[1] = new CK_ATTRIBUTE();
attributes[1].type = PKCS11Constants.CKA_ID;
attributes[1].pValue = id; //id is byteArray. For this param's value the error is causing
My question is, do I need to store any kind of key/certificate from where C_FindObjectsInit(..) will read or match as it says that it couldn't find any key? Where does this method search the key or how to resolve this issue?
Btw, I have read C_FindObjectsInit-JavaDoc and couldn't understand this line properly, that's why I am here:
pTemplate - the object's attribute values to match and the number of
attributes in search template (PKCS#11 param: CK_ATTRIBUTE_PTR
pTemplate, CK_ULONG ulCount)
[this may sound peculiar question, but I am really blank and stuck for few days]
PKCS#11 specification don't force us to use some strictly composed data.
But in most implementations I saw it was binary encoded OID field.
Also check for 0 (null) bytes in sequence.
I have the following JNA interface:
public interface MsiVersion extends StdCallLibrary {
MsiVersion INSTANCE = (MsiVersion)Native.loadLibrary( "msi", MsiVersion.class,
W32APIOptions.UNICODE_OPTIONS );
int MsiOpenDatabase( String szDatabasePath,
String szPersist,
Memory phDatabase );
}
If I open an MSI like this everything is fine:
int oparationResult = MsiVersion.INSTANCE.MsiOpenDatabase( "example.msi", "0",
dbPointerMemory );
If I try to open a patch I get error code 110. In the documentation, I found that I should somehow pass MSIDBOPEN_READONLY + MSIDBOPEN_PATCHFILE as "szPersist" instead of "0" if I would like to open a patch.
I tried to call the following based on this: http://archives.miloush.net/michkap/archive/2006/04/16/577108.html
int oparationResult = MsiVersion.INSTANCE.MsiOpenDatabase( "example.msp", "32",
dbPointerMemory );
But is still get error code 110. Can somebody help me to find the correct parameter?
Thanks,
Bálint
The problem is, that MsiOpenDatabase expects a string pointer for the szPersist parameter, but in case that a persistence mode is specified, this actually is a number casted to a string pointer.
From "msiquery.h":
#define MSIDBOPEN_READONLY (LPCTSTR)0
#define MSIDBOPEN_PATCHFILE 32/sizeof(*MSIDBOPEN_READONLY)
You are passing the string literal "32" to the szPersist parameter, but instead you need to pass it a pointer that has the value of 32:
Pointer openMode = Pointer.createConstant(32);
int operationResult = MsiVersion.INSTANCE.MsiOpenDatabase( "example.msp", openMode, dbPointerMemory );
I'm not a Java programmer, so I've just made this up from reading the reference and this FAQ (How do I get an arbitrary Pointer value?).
I'm not sure if you also have to change the JNA interface:
int MsiOpenDatabase( String szDatabasePath,
Pointer szPersist,
Memory phDatabase );
NOTE: As Heath Stewart explained, the definition in the header file "msiquery.h" is incorrect. The value of MSIDBOPEN_PATCHFILE must always be 32, even if compiling for Unicode.
You're probably running into the Ansi/Unicode issue described here:
https://blogs.msdn.microsoft.com/heaths/2006/03/31/opening-patch-files-when-compiled-for-unicode/
but to be sure you'd need to say whether you're in Unicode mode or not and your actual value for MSIDBOPEN_PATCHFILE
I have a strange problem when I'm trying execute a cypher query in an java application.
The result.dumpToString()- method shows me the correct result.
But when I'm trying to iterate, the last node is always missing (for every executed query):
for (Map<String, Object> row : result) {
System.out.println(((Node) row.get("A")));
System.out.println(((Node) row.get("A")).getProperty("name").toString());
}
The first output is correct. I see all nodes of the result.
In the second output one node is missing, although I know, that the node has a "name"-property.
Has someone an idea?
Thank you
If you're missing a second output, it's likely that the value of that property is a string that is blank. This line:
System.out.println(((Node) row.get("A")).getProperty("name").toString());
In the presence of an attribute "name" that is blank, this will print nothing at all (but a linefeed).
Also, the way you're doing this is a bit dangerous; keep in mind that in general nodes can be missing, so getProperty("name") can return null. Meaning that when you call toString() on it, you can end up with a NullPointerException. It's better to maybe write either this:
row.get("A").getProperty("name", "missing").toString();
That will return "missing" if the property is missing, or:
Object propValue = row.get("A").getProperty("name");
if(propValue != null)
System.out.println(propValue.toString());
else System.out.println("Missing name property");
Solved my problem:
I was executing the query without beginning a Transaction.
Now it works. Nevertheless this is a strange behaviour.
Thank you all
I need to clear the warning or say error message,which will be the best one to choose
setMessage(null)
or
by using StringUtils.EMPTY - i just want to know the exact way of using StringUtils.EMPTY,it would be helpful...
Thanks & Regards.
Do not use null.
Since it's a message you might showing it some where,If you set it to null,it displays as "null" to end user.
Try like ,
private static final String EMPTY_STRING = "";
setMessage(EMPTY_STRING );
on there other hand you can check with isEmpty method,instead of checking null.
I have imported an existing project into Eclipse workspace.
I have this line of code inside my existing Project.
String eod = Props.getProperty("client.eod", 5);
What is the exact meaning of the argument 5 in this call?
My guess is that if there is no property with the name client.eod whether it will set the value 5 to it. Could anybody confirm or disprove it?
Well, the docs says that the method signature is
public String getProperty(String key, String defaultValue)
hence the second argument is the default value; the docs also adds that
The method returns the default value argument if the property is not
found.
so it works as you imagined.
Yes, You are correct. But it is getProperty(String, String)
String eod = Props.getProperty("client.eod", "5");
String eod = Props.getProperty("client.eod", 5);
System.out.println("eod: "+eod);
Ya This will set the client.eod for 5.
If the value is not defined in properties file then it sets the default value.
so It gives output as below
eod:5