Class init failed in newInstance call - android-ndk

I am continuously facing a situation of which I have no idea. I am tried to test one method that I have implemented in C++. I got an error, a Class init failed when calling newInstance .
It further states that cannot load library:reloc_library[1311]:33 cannot locate 'Z13trainFacePKcS0'... and suddenly it crashes and throw exception. It gives the same error. I will appreciate any help.
Regards,
Adonis.

You have loaded a library like this in the class which gets loaded during class initialization.
static {
System.loadLibrary("gamescript");
}
From your error you have posted, it seems the library cannot be located which means, it either is not present in the apk file or it is not inside the libs folder.

Related

Mockito latest versions support to surpress static block

I am trying to add tests using latest (5.7.0) Mockito and using Mockito.mockStatic(...)
to mock class with static methods which works fine . However when I have class with static block it is unable to create mock and fais with java.lang.InternalError: class redefinition failed: invalid class .
Is this supported in latest mockito versions or still I have to live with other alternatives like powermock.
I did face the same error and couldn't find answer in the internet, so I see that it is 1 month old question but might help someone.
The problem was that mocked class (or classes that this static block used) was not in the classpath. Before you can mock the method all static blocks or fields initializators will be run, and it causes the problem.
You can verify what class is missing in your classpath by simply trying to use this static method before mocking it. You should get java.lang.NoClassDefFoundError with a class name.
When you resolve this problem, everything should work.
I had this issue, and for me it was due to an Error being thrown from instrumentation.retransformClasses called from org.mockito.internal.creation.bytebuddy.inlineBytecodeGenerator. Somewhere between there and findOrInsert in net.bytebuddy.TypeCache, the Throwable looses its context (for mockito-core 4.1.0 and bytebuddy 1.12.0)
In my case, the error being thrown was a NoClassDefFoundError for Jetty Servlet. This ultimately turned out to be a dodgy local build of a different maven module I had been working on, so clearing out my ~/.m2 and downloading a legit version fixed that right up.
You might be able to catch the Error being thrown in inlineBytecodeGenerator and taking a look at what's really going on, if this is in fact the same problem.

Trying to inject an #Client in to a Groovy Function

I'm trying to write a Micronaut AWS Groovy Lambda which makes HTTPS calls out to another service. I have followed the MN Docs and have created my project using:
mn create-function hello-world -lang groovy
This gave me a skeleton "hello-world" project with a functional test that I can run.
I then tried to modify the Groovy function (hello.world.HelloWorldFunction) to inject an HTTP client with the intention of calling the API within my function:
import static io.micronaut.http.HttpRequest.GET
#Field #Inject #Client("https://www.googleapis.com/books/v1") RxHttpClient httpClient
Maybe<String> helloWorld() {
httpClient.retrieve(GET("/volumes?q=isbn:0747532699"))
.firstElement()
}
Having done this I now get an exception when I run the functional test:
08:51:25.269 [nioEventLoopGroup-1-5] ERROR
i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred:
Failed to inject value for field [httpClient] of class:
hello.world.HelloWorldFunction
Path Taken: HelloWorldFunction.httpClient
io.micronaut.context.exceptions.DependencyInjectionException: Failed to inject value for field [httpClient] of class:
hello.world.HelloWorldFunction
Path Taken: HelloWorldFunction.httpClient
I'm almost certainly doing something wrong, but I'm at a bit of a loss in terms of how to figure out what. Hence grateful for any pointers.
Many thanks,
Edd
Found the answer to this. It's a bug in 1.0.0.M1. It's already fixed in master though so can be worked around by building Micronaut from source and using that.
In addition I discovered that I was returning a type that is unsupported by Lambda functions (Maybe<String>). After building MN from master and changing this to a supported return type everything is now working.

Why Acumatica can't find method

I'm working with Acumatica 5.30.2347. I have following selector in my graph:
var check = PXSelect<POLine,Where<POLine.orderType, Equal<POOrderType.regularOrder>>>
.Select(this);
but when I try to execute it, I receive following error:
Method not found: 'Void PX.Data.PXLineAttribute..ctor'(System.Type).
Initially I've got an impression, that this error message appeared because class PXLineAttribute doesn't have constructor which accepts System.Type, but with help of reflector I've discovered that PXLineAttribute has following declaration:
public PXLineNbrAttribute(System.Type sourceType)
: this(sourceType, false)
{
}
which gives me idea that PXLineNbrAttribute has needed constructor. So I have two questions: Why Acumatica Framework can't find constructor of PXLineNbrAttribute? How to help Acumatica to find before mentioned constructor?
Please check your VS class library project references to Acumatica assemblies. I would suspect them to reference assemblies from a different Acumatica build and therefore cause "Method not found ..." errors at runtime.

Groovy Grape dealing with dependency resolution

I am trying to use org.xhtmlrenderer:core-renderer:R8pre2 in a groovy script, but I get a Linkage error:
Caught: java.lang.LinkageError: loader constraint violation in interface
itable initialization: when resolving method
"org.apache.xerces.dom.NodeImpl.getOwnerDocument()Lorg/w3c/dom/Document;"
the class loader (instance of org/codehaus/groovy/tools/RootLoader) of the
current class, org/apache/xerces/dom/NodeImpl, and the class loader (instance of
<bootloader>) for interface org/w3c/dom/Node have different Class objects for
the type getOwnerDocument used in the signature
I've already googled a lot and found a lot of answer like these:
Dealing with "Xerces hell" in Java/Maven?
XercesImpl in conflict with JavaSE 6's internal xerces implementation. Both are needed... what can be done?
So, one solution could be to use javas endorsed mechanism to resolve the conflict, but I would like to make my script independent from such a "workaround". The script should run out of the box.
Next thing I was giving a try was to exclude the right dependency like this
#Grapes([
#Grab('org.xhtmlrenderer:core-renderer:R8pre2'),
#GrabExclude('xml-apis:xml-apis')
])
but didn't succeed...
Any ideas?
PS: here is the script which creates the error:
#Grapes([
#Grab('org.xhtmlrenderer:core-renderer:R8pre2'),
])
import org.w3c.dom.Document
import javax.xml.parsers.DocumentBuilder
import javax.xml.parsers.DocumentBuilderFactory
def dbf = DocumentBuilderFactory.newInstance()
DocumentBuilder builder = dbf.newDocumentBuilder()
Document doc = builder.parse(new ByteArrayInputStream("<html></html>".getBytes()))
Thanx to #dmahapatro, I checked my configuration and found that I dropped some jars in {usrhome}/.groovy a long time ago. Removed these and now everything work like a charm...

Error calling method in java-class 'ClassA' 'org.my.ClassB' is incompatible with 'org.my.ClassB'

I have two classes org.my.ClassA and org.my.ClassB both classes are in the same package org.my in the WEB-INF/src in the same database.
ClassA has the method public add(org.my.ClassB newB){...}.
In SSJS I have a code block in which I call ClassA.add(ClassB) which normally works fine. Until some unknown point where the Server can't see that org.my.ClassB === org.my.ClassB and it returns the error (message translated from German maybe looks different in English version):
error calling method 'add(org.my.ClassB)' in java-class 'ClassA'.
'org.my.ClassB' is incompatible with 'org.my.ClassB'.
and it points to my line in the SSJS: ClassA.add(ClassB);
What I tried so far:
First I added the line importPackage(org.my); to my SSJS Code. No luck.
I tried to add another method add(Object newB) and then cast the object to ClassB but same result. The error does not seem to come from the java class its from the SSJS code because it cant find the method with an argument of the type org.my.ClassB. But if I test the object in the SSJS code it returns org.my.ClassB.
Then I tried to add the classpath to all variables in the SSJS block like: var newB:org.my.ClassB = new org.my.ClassB(). But same result after some time the application breaks with the same error.
From my Point of view it got to do something with the caching of compiled classes, or so because if I clear the database everything works just fine again.
Hope someone has a solution on this.
This is a class loader problem.
You can find more details about the issue in the answer from Frantisek Kossuth:
See here more details: Meaning of java.lang.ClassCastException: someClass incompatible with someClass

Resources