Why is php decimal-ext throwing an exception for wrong return type of compareTo method? - laravel

I've installed decimal-ext extension and php-decimal/laravel composer package. I'm using it to compare large decimal numbers. On my laptop everything works correctly but on my staging server the following error is thrown:
Return value of Decimal\Decimal::compareTo() must be of the type int, none returned
and here is the code:
(new Decimal($value))->compareTo($maxNumber) == -1;
As I said I'm not getting this error on my laptop.
Laravel: 5.8
PHP: 7.4.3
Server: Ubuntu 18.04

I spent some time on this but figured it out. The decimal-ext extension was not loaded in the server's php.ini file. Php didn't throw an exception about missing extension but about the wrong return type because the class Decimal was actually loaded (it was installed via the composer). I could instantiate an instance but the implementation was missing:
/**
* Ordering
*
* This method is equivalent to the `<=>` operator.
*
* #param mixed $other
*
* #return int 0 if this decimal is considered is equal to $other,
* -1 if this decimal should be placed before $other,
* 1 if this decimal should be placed after $other.
*/
public function compareTo($other): int {}

Related

laravel migration error while creating new one

i tried creating new migration and in my migration file i got the following text
/**
* Gets the first element of `array`.
*
* #static
* #memberOf _
* #since 0.1.0
* #alias first
* #category Array
* #param {Array} array The array to query.
* #returns {*} Returns the first element of `array`.
* #example
*
* _.head([1, 2, 3]);
* // => 1
*
* _.head([]);
* // => undefined
*/
function head(array) {
return (array && array.length) ? array[0] : undefined;
}
module.exports = head;
instead of the normal migration code,
i tried installing the composer , composer dump-autoload
tried clearing cache
but still no luck , it was not like this earlier as i have created many migrations and they were working fine but suddenly it gave me this error,
any idea what is causing this error

Ignite - explain about 31100 time server port

Can anyone please explain, why the ignite is using the 31100 port. I have got the info in web as it is a time server port. I couldn't get anything other than this info.
I see following configuration options in Ignite project:
/** Base port number for time server. */
private int timeSrvPortBase = DFLT_TIME_SERVER_PORT_BASE; // 31100
/** Port number range for time server. */
private int timeSrvPortRange = DFLT_TIME_SERVER_PORT_RANGE; // 100
/**
* Gets base UPD port number for grid time server. Time server will be started on one of free ports in range
* {#code [timeServerPortBase, timeServerPortBase + timeServerPortRange - 1]}.
* <p>
* Time server provides clock synchronization between nodes.
*
* #return Time
*/
public int getTimeServerPortBase() {
return timeSrvPortBase;
}
/**
* Defines port range to try for time server start.
*
* If port range value is <tt>0</tt>, then implementation will try bind only to the port provided by
* {#link #setTimeServerPortBase(int)} method and fail if binding to this port did not succeed.
*
* #return Number of ports to try before server initialization fails.
*/
public int getTimeServerPortRange() {
return timeSrvPortRange;
}
But I don't see any usage of this methods in other places. Looks like and obsolete feature. I've just started one server node of 2.10 and didn't see any open ports in range 311xx (sudo netstat -atnp | grep 311[0-9][0-9] was empty). Are you sure that your Ignite instance exposes this port? What version do you use?

#returns throwing error when running locally on docker

I'm trying to return array of asset from transaction. So as per the syntax I have added #returns and #commit(false) in cto file but its throwing error as
✖ Installing business network. This may take a minute...
ParseException: Expected ")", "-", "false", "true", comment, end of
line, number, string or whitespace but "P" found. File
models/org.zcon.healthcare.cto line 370 column 10
Command failed
And when i'm removing the #returns annotation its not throwing any error.
And well its not throwing any error when i'm removing parameter "Patient[]" from #returns annotation.. But it's against the syntax right?
I'm running the application locally using docker swarm.
My docker composer version is v0.19.12
What's wrong? Is this any bug?
In case if you want to see the transaction definition in cto file.
#commit(false)
#returns(Patient[])
transaction SearchPatient{
o String firstName optional
o String lastName optional
}
And in logic file
/**
* Sample transaction
* #param {org.zcon.healthcare.SearchPatient} tx
* #returns{org.zcon.healthcare.Patient[]}
* #transaction
*/
async function SearchPatient(tx){
let queryString = `SELECT org.zcon.healthcare.Patient WHERE (`;
let conditions = [];
if (tx.hasOwnProperty('firstName')) {
var firstName =tx.firstName;
conditions.push(`(firstName == "${firstName}")`)
};
if (tx.hasOwnProperty('lastName')) {
var lastName = tx.lastName;
conditions.push(`(lastName == "${lastName}")`)
};
queryString += conditions.join(' AND ') + ')';
let finalQuery = buildQuery(queryString);
const searchPatient = await query(finalQuery);
if(searchPatient.length ==0){
throw "No Patient Records found!!"
}else
return searchPatient;
}
I've not seen this error with composer network install (deploying to a running Fabric) I did the network install just fine (see screenshot) with your model and code. I suggest that your error may lie elsewhere in your business network ? Can you add the complete sequence of what you got to get the error? How did you build your bna file?
I also tried your code (ending....):
const searchPatient = await query(finalQuery);
console.log("results are " + searchPatient);
console.log("element 1 of array is " + searchPatient[0]);
if(searchPatient.length ==0){
throw "No Patient Records found!!"
} else
return searchPatient;
}
and can see the returned results fine (as shown in console.log - just using a different network name obviously FYI)

Is java.text.BreakIterator thread-safe in openjdk?

I ran into some weird threading issues in a continuous integration build on travis-ci and got:
testThatDifferentArgumentsCanBeParsedConcurrently(se.softhouse.jargo.concurrency.ConcurrencyTest) Time elapsed: 0.479 sec <<< FAILURE!
org.junit.ComparisonFailure: expected:<... greeting phrase to [
]greet new connection...> but was:<... greeting phrase to []greet new connection...>:<... greeting phrase to []greet new connection...>
It only seems to go wrong with openjdk and not with oraclejdk.
And here's my code that's using BreakIterator:
/**
* Wraps lines where <a
* href="http://docs.oracle.com/javase/tutorial/i18n/text/line.html">appropriate</a> (as defined
* by {#code locale}).
*
* #param value the value to separate with {#link StringsUtil#NEWLINE new lines}
* #param startingIndex the index where each line starts, useful for a fixed-size table for
* instance
* #param maxLineLength how long each line are allowed to be
*/
public static StringBuilder wrap(CharSequence value, int startingIndex, int maxLineLength, Locale locale)
{
String textToSplit = value.toString();
StringBuilder result = new StringBuilder(textToSplit.length());
// TODO(jontejj): is this not thread safe?
BreakIterator boundary = BreakIterator.getLineInstance(locale);
boundary.setText(textToSplit);
int start = boundary.first();
int end = boundary.next();
int lineLength = startingIndex;
while(end != BreakIterator.DONE)
{
String word = textToSplit.substring(start, end);
lineLength = lineLength + word.length();
if(lineLength >= maxLineLength)
{
result.append(NEWLINE);
lineLength = startingIndex;
}
result.append(word);
start = end;
end = boundary.next();
}
return result;
}
It seems like java.text.BreakIterator didn't do it's job and stretched the line for more characters than it should have.
I checked the openjdk version of both BreakIterator and RuleBasedBreakIterator but couldn't identify any apparent thread safety issues. There are some arrays in RuleBasedBreakIterator that aren't deeply cloned but I couldn't see that they are modified so that should be safe. I could not find the oraclejdk source code. Have I understood it wrong that there shouldn't be as big differences between them as there used to be?
I tried to isolate the issue with a specific test for BreakIterator usage but so far that hasn't been fruitful.
Sorry for the kind of awkward question but I'm at a standstill so I thought that maybe someone on stackoverflow could help.

Can I read JavaScript alert box with WatiN?

I want to use WatiN to verify the error message in a JavaScript alert box. Is this possible? Thanks.
see Trev's Blog and here as well.
using(IE ie = new IE("http://hostname/pagename.htm"))
{
AlertDialogHandler alertDialogHandler = new AlertDialogHandler();
using (new UseDialogOnce(ie.DialogWatcher, alertDialogHandler ))
{
/*************************************
* -- alert -- *
* *
* must use the "NoWait" to allow *
* the code to goto the next line *
* *
*************************************/
alertDialogHandler.WaitUntilExists();
alertDialogHandler.OKButton.Click();
ie.WaitForComplete();
}
}

Resources