Using cordova 2.6, i am calling a plugin using cordova.exec.
The issue is that the parameters if passed in an array element are being cut(truncated from the end by some characters) at the java side.
but if i pass a simple string as a parameter its being passed perfectly fine.
Passed 5714 characters in string and its going without any isues, but passing 450 characters in an array's first element is cutting the array into about 1/4th of its original length(119) .
Then tried the following :
Converted the first array element into string.(Checked the typeof using javascript) and passed but did not help.
Created a substring of the original array and passed static limits to the substring i.e substring(0,4000) etc etc, but to no luck.
Made a clone of the original array and repeated steps 1 and 2 but again no luck.
Could someone tell me where the issue is?
Increased eclipse heap memory and changed to cordova 2.8.1 too, but the same result. :(
I got the reason for the behaviour. Inspected many images , and in my execute method of plugin did the following :
int myLength = args.getString(0).length();
Log.v(TAG,Character.toString(args.getString(0).charAt(myLength-1)));
Got the character as = on the plugin/java side. And an = is inserted in the base64 string at the end of it. It seems that cordova is inserting these delimeters in the base64string.
P.S. :Went through phonegap.js and found that the arguments are being packed as JSON.stringify , and after that could not get more. That how and where the = is inserted.
Related
I've "inherited" existing Java Selenium & Cucumber framework which was written mostly for OS usage. I'm using Windows and I'm trying to fix & run it on Windows.
My first problem is specifing corrent file path, this is how it was written for OS:
private String getProjectName(Scenario scenario) {
return Arrays.asList(scenario.getUri().getPath().replace(System.getProperty("user.dir"), "").split("/")).get(5);
}
Error which I'm receiving is:
java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 1
As for Windows we're using backlashes I've tried switching "/" into "" but as error appears (+ after my investigations) I've tried with "\\\\" but actually error remains the same as above.
I'm aware that providing only portion of my code and it may be hard but for the first glance can you tell me:
If that method may work on Windows or this should be completely refactored?
Is System.getProperty("user.dir") correct solution?
How to correctly pass backslashes?
Why they're taking .get(5)?
I can guess:
This method is taking the project name that is likely the name of a certain folder in the folder structure where scenario file located.
This is why they took 5th element. Because on the 5th level there was the folder which represented the project.
The used approach look very arguable. At least because there are some redundent steps like converting to list.
Now. How would you go:
The proper way is to use java.nio.file.Path (starts from Java 7) that takes care of differnt OS-specific things.
So your code might look like:
private String getProjectName(Scenario scenario) {
return Path.of(scenario.getUri()).getName(5)
}
P.S. - of course you have to change 5 to catch a proper position of the required folder in your structure.
I think I am copying the answer from here, but I still cannot get optional parameters to work. The two steps run independently, I just wanted to try and combine them.
Scenario:
Then(~/^set timeout(?: at (\d+) (min|hr))?$/) { int duration , String units ->
Works for
And set timeout at 30 min
But not for:
And set timeout
Which throws this error
groovy.lang.MissingMethodException: No signature of method: CucumberTestSteps$_run_closure56.doCall() is applicable for argument types: (null, null) values: [null, null]
Possible solutions: doCall(int, java.lang.String), findAll(), findAll()
I've tried several other random locations for '?:' and '?' with no luck. Also several web searches which all come back to that syntax should work.
Cucumber recognizes it as a valid test because when I add
Then(~/^set timeout$/)
It recognises it as a duplicate step
cucumber.runtime.AmbiguousStepDefinitionsException: ✽.Then set timeout(test.feature:57) matches more than one step definition:
^set timeout$ in CucumberTestSteps.groovy:1128
^set timeout(?: at (\d+) (min|hr))?$ in CucumberTestSteps.groovy:1148
I know I'm too late for this answer, but I had the same issue today and was able to resolve it. Hopefully, this answer will help those looking for the solution to this problem. Apparently, in case of optional parameters, it passes null values to the parameters.
The problem happens because your method has an int instead of Integer. In my case, I changed the int to Integer and did a null check before proceeding. That solved the issue.
When debugging a java program in Eclipse, I can see (e.g. in the Variables view) the content of an arbitrary array, see the picture bellow (with the ByteArrayInputStream.buf field).
But I cannot find the array length field anywhere. Is there a way to show the length of an array in Eclipse debugger? How can I do it?
You can use the "Expressions" view and evaluate the length member:
Keep in mind that the last index is one less than the length!
While this works for public array members, it seems that an explicit cast is required for protected members. Consider the following code:
...
ByteArrayInputStream is = new ByteArrayInputStream(new byte[1769]);
...
Now, when evaluating is.buf, the Expressions view shows a dump of the array as shown in the question, but evaluating is.buf.length fails with <error(s)_during_the_evaluation>. If we add an explicit cast to ByteArrayInputStream, the evaluation works:
Thank you #ThorbjørnRavnAndersen for your answer (comment). You are right, the latest array segment (in my case: [1700..1768]) holds the length.
The whole picture:
I am currently trying to perform some regex on the result of a DatagramPacket.getData() call.
Implemented as String myString = new String(thepkt.getData()):
But weirdly, java is dropping the end quotation that it uses to encapsulate all data(see linked image below).
When I click the field in the variable inspector during a debug session and don't change anything, when I click off the variable field it corrects itself again without me changing anything. It even highlights the variable inspection field in yellow to signal change.
Its values are also displaying like it is still a byte array rather than a String object
http://i.imgur.com/8ZItsZI.png
It's throwing off my regex and I can't see anything that would cause it. It's a client server simulation and on the client side, the getData returns the data no problem.
I got it working by using the solution provided in:
https://stackoverflow.com/a/8557165/1700855
But I still don't understand how not specifying the length of the packet to the String constructor would cause it to drop the systematic end double quotes. Can anyone provide an explanation as I really like to understand solutions to my issues before moving on :)
The problem is that you didn't read the spec for DatagramPacket.getData:
Returns the data buffer. The data received or the data to be sent
starts from the offset in the buffer, and runs for length long.
So, to be correct, you should use
new String(thepkt.getData(), thepkt.getOffset(), thepht.getLength())
Or, to not use the default charset:
new String(thepkt.getData(), thepkt.getOffset(), thepht.getLength(), someCharset)
I am using a lib which has an enum type with consts like these;
Type.SHORT
Type.LONG
Type.FLOAT
Type.STRING
While I am debugging in Eclipse, I got an error:
No enum const class Type.STRİNG
As I am using a Turkish system, there is a problem on working i>İ but as this is an enum const, even though I put every attributes as UTF-8, nothing could get that STRING is what Eclipse should look for. But it still looks for STRİNG and it can't find and I can't use that. What must I do for that?
Project > Properties > Resouce > Text file encoding is UTF-8 now. Problem keeps.
EDIT: More information may give some clues which I can't get;
I am working on OrientDB. This is my first attempt, so I don't know if the problem could be on OrientDB packages. But I am using many other libs, I have never seen such a problem. There is a OType enum in this package, and I am only trying to connect to the database.
String url = "local:database";
ODatabaseObjectTx db = new ODatabaseObjectTx(url).
Person person = new Person("John");
db.save(person);
db.close();
There is no more code I use yet. Database created but then I get the java.lang.IllegalArgumentException:
Caused by: java.lang.IllegalArgumentException: No enum const class com.orientechnologies.orient.core.metadata.schema.OType.STRİNG
at java.lang.Enum.valueOf(Unknown Source)
at com.orientechnologies.orient.core.metadata.schema.OType.valueOf(OType.java:41)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLCreateProperty.parse(OCommandExecutorSQLCreateProperty.java:81)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLCreateProperty.parse(OCommandExecutorSQLCreateProperty.java:35)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:43)
at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.parse(OCommandExecutorSQLDelegate.java:28)
at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OStorageEmbedded.java:63)
at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:63)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.addProperty(OClassImpl.java:342)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.createProperty(OClassImpl.java:258)
at com.orientechnologies.orient.core.metadata.security.OSecurityShared.create(OSecurityShared.java:177)
at com.orientechnologies.orient.core.metadata.security.OSecurityProxy.create(OSecurityProxy.java:37)
at com.orientechnologies.orient.core.metadata.OMetadata.create(OMetadata.java:70)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.create(ODatabaseRecordAbstract.java:142)
... 4 more
Here is OType class: http://code.google.com/p/orient/source/browse/trunk/core/src/main/java/com/orientechnologies/orient/core/metadata/schema/OType.java
And other class; OCommandExecutorSQLCreateProperty:
http://code.google.com/p/orient/source/browse/trunk/core/src/main/java/com/orientechnologies/orient/core/sql/OCommandExecutorSQLCreateProperty.java
Line 81 says: type = OType.valueOf(word.toString());
Am I correct to assume you are running this program using a turkish locale? Then it seems the bug is in line 118 of OCommandExecutorSQLCreateProperty:
linkedType = OType.valueOf(linked.toUpperCase());
You would have to specify the Locale whose upper casing rules should be used, probably Locale.ENGLISH as the parameter to toUpperCase.
This problem is related to your database connection. Presumably, there's a string in OrientDB somewhere, and you are reading it, and then trying to use it to select a member of the enum.
I'm assuming in the code that you posted that the variable word comes from data in the database. If it comes from somewhere else, then the problem is the 'somewhere else'. If OrientDB, for some strange reason, returns 'STRİNG' as metadata to tell you the type of something, then that is indeed a defect in OrientDB.
If that string actually contains a İ, then no Eclipse setting will have any effect on the results. You will have to write code to normalize İ to I.
If you dump out the contents of 'word' as a sequence of hex values for the chars of the string, I think you'll see your İ staring right at you. You have to change what's in the DB to have a plain old I.
Unfortunately, it is related with regional setting, locale of your OS which is Turkish.
Two work around options :
1. Change your regional settings to English-US
2. Give encoding to the jvm as command line param for setting locale to English
-Duser.language=en -Duser.region=EN
I have created bug reports for xmlbeans, exist and apache cxf for the same issue. Enumeration toUpper is the point of the exception.
Some related links:
https://issues.apache.org/jira/browse/XMLSCHEMA-22
http://mail-archives.apache.org/mod_mbox/xmlbeans-user/201001.mbox/%3CSNT123-DS11993DD331D6CA7799C46CF6650#phx.gbl%3E
http://mail-archives.apache.org/mod_mbox/cxf-users/201203.mbox/%3CBLU0-SMTP115A668459D9A0DA11EA5FAF6460#phx.gbl%3E
https://vaadin.com/forum/-/message_boards/view_message/793105
http://comments.gmane.org/gmane.comp.apache.cxf.user/18316
One work-around is to type Type.ST and then press Ctrl-space. Eclipse should auto-complete the variable name without you having to figure out how to enter a dotless capital I on a Turkish keyboard. :)