Reputation: 11
I am after upgrading PHP 7.4 to 8.2 due to vulnerabilities. I am having a dilemma with one of our legacy web apps that creates PDF report using jasperReport.
I'm getting the following error -
Fatal error: Uncaught Error: Attempt to assign property "currentCacheKey" on null in http://servername:8080/JavaBridge/java/Java.inc:1999 Stack trace: #0 D:\xampp\htdocs\wip_live\javabridge.php(84): Java->__call('forName', Array) #1 {main} thrown in http://servername:8080/JavaBridge/java/Java.inc on line 1999
And below is a snippet of the code in Java.inc
function __call($method,$args) {
$client=$this->__client;
$sig="@{$this->__signature}@$method";
$len=count($args);
$args2=array($this->__java);
for($i=0; $i<$len; $i++) {
switch(gettype($val=$args[$i])) {
case 'boolean': array_push($args2,$val); $sig.='@b'; break;
case 'integer': array_push($args2,$val); $sig.='@i'; break;
case 'double': array_push($args2,$val); $sig.='@d'; break;
case 'string': array_push($args2,htmlspecialchars($val,ENT_COMPAT)); $sig.='@s'; break;
case 'array':$sig="~INVALID"; break;
case 'object':
if($val instanceof java_JavaType) {
array_push($args2,$val->__java);
$sig.="@o{$val->__signature}";
}
else {
$sig="~INVALID";
}
break;
case 'resource': array_push($args2,$val); $sig.='@r'; break;
case 'NULL': array_push($args2,$val); $sig.='@N'; break;
case 'unknown type': array_push($args2,$val); $sig.='@u'; break;
default: throw new java_IllegalArgumentException($val);
}
}
if(array_key_exists($sig,array($client->methodCache))) {
$cacheEntry=&$client->methodCache[$sig];
$client->sendBuffer.=$client->preparedToSendBuffer;
if(strlen($client->sendBuffer)>=JAVA_SEND_SIZE) {
if($client->protocol->handler->write($client->sendBuffer)<=0)
throw new java_IllegalStateException("Out of sync. Check backend log for details.");
$client->sendBuffer=null;
}
$client->preparedToSendBuffer=vsprintf($cacheEntry->fmt,$args2);
if($cacheEntry->resultVoid) {
$client->cancelProxyCreationTag +=1;
return null;
} else {
$result=clone($client->cachedJavaPrototype);
$result->__factory=$cacheEntry->factory;
$result->__java=++$client->asyncCtx;
$result->__signature=$cacheEntry->signature;
$result->__cancelProxyCreationTag=++$client->cancelProxyCreationTag;
return $result;
}
} else {
$client->currentCacheKey=$sig; //!!!this is where the code breaks!!!
$retval=parent::__call($method,$args);
return $retval;
}
}
}
There is a PHP file calling Java functions on Java.inc and below is the snippet of it
require_once(TOMCAT_SERVER_JAVA_INC."/JavaBridge/java/Java.inc");
$connection = new Java("java.sql.Connection");
$class = new Java("java.lang.Class");
$class->forName("com.mysql.jdbc.Driver"); //!!!this is the function call where the code breaks!!!
I've read that there are significant changes on compatibility, and this is a legacy web application which was developed by someone who no longer works here.
So far, I tried disabling reports for fatal error but it only did silence the reporting.
Upvotes: 1
Views: 200
Reputation: 11
Found the fix for this issue. For anyone having the same issue as above, just replace the Java.inc file with the newer version available in
There are a number of changes on the new code including proper use of __construct in function declaration. And it seems to me that they include the encoding "ISO-8859-1" as parameter on the htmlspecialchars() function which i think was causing the issue.
https://www.php.net/manual/en/function.htmlspecialchars.php
Upvotes: 0