Jni exception ---- Bogus method descriptor? - java-native-interface

I try to call a java method in cpp code:
In cpp code:
jclass m_cls = env->FindClass("icm/bdroid/jni/Element");
jmethodID m_mid_addElement = env->GetMethodID(m_cls,"AddElement","(icm/bdroid/jni/Element:)V");
The Java code:
public void AddElement(Element e) {
Get following exception:
12-07 04:21:00.051: W/dalvikvm(31880): Bogus method descriptor:
(icm/bdroid/jni/Element:)V
12-07 04:21:00.051: W/dalvikvm(31880): Bogus method descriptor:
(icm/bdroid/jni/Element:)V
12-07 04:21:00.051: D/dalvikvm(31880): GetMethodID: method not found:
Licm/bdroid/jni/Element;.AddElement:(icm/bdroid/jni/Element:)V
12-07 04:21:00.051: W/dalvikvm(31880): JNI WARNING: JNI method called
with exception raised
12-07 04:21:00.051: W/dalvikvm(31880): in
Licm/bdroid/jni/Jni;.parseScore (J)Licm/bdroid/jni/Element;
(NewObjectV)

I think it should be:
env->GetMethodID(m_cls,"AddElement","(Licm/bdroid/jni/Element;)V");

Check "Type Signatures" section of https://docs.oracle.com/javase/8/docs/technotes/guides/jni/spec/types.html
L fully-qualified-class ; fully-qualified-class

An easy way to get method signatures is the javap utility:
javap -cp your.jar -s fully.qualified.class.Name

Related

Can not access data from given OIDs using net-snmp

i implemented the simple net-snmp simple application into my project. when i tried to use the example OID given at the site: .1.3.6.1.2.1.1.1.0 it worked just fine.
now i need to get data from these oids: https://www.sysadmin.md/snmp-most-useful-linux-oids.html. when i tried to implement these oids into my code i got error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV).
the simple application code:
add_mibdir(".");
pdu = snmp_pdu_create(SNMP_MSG_GET);//creating a get pdu
if(read_objid(".1.3.6.1.4.1.2021.11.9", id_oid, &id_len)==1)//specifying the oid we want to receive
cout<<"oid read"<<endl;
else
cout<<"couldnt read oid"<<endl;
snmp_add_null_var(pdu, id_oid, id_len);//making room for the response
status = snmp_synch_response(session_handle, pdu, &response);//getting the response
cout<<"status: "<<status<<endl;
string ReturnBuffer;
cout<<"vars: "<<vars->val.string<<endl;
for(vars = response->variables; vars; vars = vars->next_variable)//printing the values we got back
{
cout<<vars->val.string<<endl;
ReturnBuffer.append(reinterpret_cast<char*>(vars->val.string));
}
ReturnBuffer.append("\0"); //test
return ReturnBuffer;
according to the code the oid itself is read and the status of the response is 0 and yet im not getting any of the data and got the error above, i'd appreciate any help thanks in advance.
language: c++
os: linux(ubuntu)

How to make Armeria exit on an `Address already in use` error?

How do I make sure that my program exits when Armeria fails to start because of an Address already in use error?
I have the following code:
import com.linecorp.armeria.common.HttpRequest;
import com.linecorp.armeria.common.HttpResponse;
import com.linecorp.armeria.server.AbstractHttpService;
import com.linecorp.armeria.server.Server;
import com.linecorp.armeria.server.ServerBuilder;
import com.linecorp.armeria.server.ServiceRequestContext;
import java.util.concurrent.CompletableFuture;
public class TestMain {
public static void main(String[] args) {
ServerBuilder sb = Server.builder();
sb.http(8080);
sb.service("/greet/{name}", new AbstractHttpService() {
#Override
protected HttpResponse doGet(ServiceRequestContext ctx, HttpRequest req) throws Exception {
String name = ctx.pathParam("name");
return HttpResponse.of("Hello, %s!", name);
}
});
Server server = sb.build();
CompletableFuture<Void> future = server.start();
future.join();
}
}
When I run it once everything is fine.
But when I run it the second time I get an Address already in use error, which is of course expected, but the program doesn't terminate on its own. This may be how it is supposed to be, but how do I make sure that it terminates upon errors during initialization?
$ gradle run
> Task :run
14:36:04.811 [main] DEBUG io.netty.util.internal.logging.InternalLoggerFactory - Using SLF4J as the default logging framework
14:36:04.815 [main] DEBUG io.netty.util.internal.PlatformDependent0 - -Dio.netty.noUnsafe: false
14:36:04.816 [main] DEBUG io.netty.util.internal.PlatformDependent0 - Java version: 8
14:36:04.817 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.theUnsafe: available
14:36:04.817 [main] DEBUG io.netty.util.internal.PlatformDependent0 - sun.misc.Unsafe.copyMemory: available
14:36:04.818 [main] DEBUG io.netty.util.internal.PlatformDependent0 - java.nio.Buffer.address: available
...
14:36:05.064 [globalEventExecutor-3-1] DEBUG io.netty.buffer.PooledByteBufAllocator - -Dio.netty.allocator.maxCachedByteBuffersPerChunk: 1023
14:36:05.068 [globalEventExecutor-3-1] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.allocator.type: pooled
14:36:05.068 [globalEventExecutor-3-1] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.threadLocalDirectBufferSize: 0
14:36:05.068 [globalEventExecutor-3-1] DEBUG io.netty.buffer.ByteBufUtil - -Dio.netty.maxThreadLocalCharBufferSize: 16384
Exception in thread "main" java.util.concurrent.CompletionException: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
at java.util.concurrent.CompletableFuture.encodeRelay(CompletableFuture.java:326)
at java.util.concurrent.CompletableFuture.completeRelay(CompletableFuture.java:338)
at java.util.concurrent.CompletableFuture.uniRelay(CompletableFuture.java:911)
at java.util.concurrent.CompletableFuture.uniCompose(CompletableFuture.java:953)
at java.util.concurrent.CompletableFuture$UniCompose.tryFire(CompletableFuture.java:926)
at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:474)
at java.util.concurrent.CompletableFuture.postFire(CompletableFuture.java:561)
at java.util.concurrent.CompletableFuture$UniWhenComplete.tryFire(CompletableFuture.java:739)
at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442)
at io.netty.util.concurrent.GlobalEventExecutor$TaskRunner.run(GlobalEventExecutor.java:250)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.lang.Thread.run(Thread.java:748)
Caused by: io.netty.channel.unix.Errors$NativeIoException: bind(..) failed: Address already in use
<==========---> 80% EXECUTING [6s]
> :run
^C
It's a bug in Armeria, where Netty event loop threads are not terminated when a Server fails to start up. Here's the fix PR, which should be part of the next release (0.97.0): https://github.com/line/armeria/pull/2288

NoClassDefFoundError encountered while fixing CRLF sequence in HttpHeader

After performing Vera code scan on my code, a flaw was reported saying " Improper Neutralization of CRLF Sequences in HTTP Headers ('HTTP Response Splitting - CWE ID 113') on the below code.
public void writeCookies() {
for (final Cookie cookie : cookies) {
super.addCookie(cookie);
}
The flaw code reported is super.addCookie(cookie). To fix this I added below code
public void writeCookies() {
for (final Cookie cookie : cookies) {
cookie.setSecure(true);
ESAPI.httpUtilities().addCookie(((HttpServletResponse)super.getResponse()),cookie);
}
}
Now the Veracode scan doesn't report any flaw in the code. However, while running the application, I get NoClassDefFoundError as below
Error Message: javax.servlet.ServletException:
java.lang.NoClassDefFoundError:
org.apache.commons.fileupload.FileItemFactory Error Code: 500 Target
Servlet: com.ibm.ws.webcontainer.extension.DefaultExtensionProcessor
Error Stack: java.lang.NoClassDefFoundError:
org.apache.commons.fileupload.FileItemFactory
at java.lang.J9VMInternals.verifyImpl(Native Method)
at java.lang.J9VMInternals.verify(J9VMInternals.java:94)
at java.lang.J9VMInternals.initialize(J9VMInternals.java:171)
at java.lang.Class.forNameImpl(Native Method)
at java.lang.Class.forName(Class.java:180)
at org.owasp.esapi.util.ObjFactory.make(ObjFactory.java:74)
at org.owasp.esapi.ESAPI.httpUtilities(ESAPI.java:121)
My ESAPI.properties file is at location src/main/resources/ESAPI.properties
The content of ESAPI.properties file is
*
Encoder.AllowMultipleEncoding=false Encoder.AllowMixedEncoding=false
Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
ESAPI.HTTPUtilities=org.owasp.esapi.reference.DefaultHTTPUtilities
*
Please suggest me on how to fix this NoClassDefFoundError...

How to remove special character in the string

This could be a possbile duplicate. Still im not able to find a solution for it.Yes i tried with regexp but is there any other way to solve it?
String s="This is a â¦sample ⦠Java class to show the issueâ¨\nHow to solve it?";
try {
System.out.print("ANSWER="+URLDecoder.decode(s, "UTF-8")); ;
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
How can i fix this issue? Can some one help
Thanks in advance
The console output
Invalid layout of java.lang.String at value
#
# A fatal error has been detected by the Java Runtime Environment:
#
# Internal Error (javaClasses.cpp:136), pid=17620, tid=14220
# fatal error: Invalid layout of preloaded class
#
# JRE version: (7.0_79-b15) (build )
# Java VM: Java HotSpot(TM) 64-Bit Server VM (24.79-b02 mixed mode windows-amd64 compressed oops)
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
Try this
String yourString= "This is a â¦sample ⦠Java class to show the issueâ¨\nHow to solve it?";
Pattern myPattern = Pattern.compile("[^a-zA-Z0-9]");
Matcher myMatcher = myPattern.matcher(yourString);
while(myMatcher.find())
{
String temp= myMatcher.group();
yourString=yourString.replaceAll("\\"+temp, " ");
}
System.out.println(yourString);

Cakephp 3.0 Unit testing Issue

When i execute the plugins/SamplePlugin test cases, it executing perfect except the controller functions which are related to urls.
The test case function like
public function testIndex()
{
$this->get('/sample-plugin /mycontroller/index');
$this->assertResponseOk();
}
when i execute the above testcase the exception
There was 1 error:
1) SamplePlugin\Test\TestCase\Controller\MyControllerTest::test
Index
include(D:\xampp\htdocs\EATZ_V2_3.X\vendor\cakephp\cakephp\tests\test_app\config\routes.php): failed to open stream: No such file or directory
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\Routing\Router.php:974
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\Routing\Router.php:974
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\Routing\Router.php:547
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:451
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:392
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:312
D:\xampp\htdocs\MyApp\vendor\cakephp\cakephp\src\TestSuite\IntegrationTestCase.php:233
D:\xampp\htdocs\MyApp\plugins\SamplePlugin\tests\TestCase\Controller\MyControllerTest.php:29
D:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
D:\xampp\php\pear\PHPUnit\TextUI\Command.php:129
FAILURES!
Tests: 30, Assertions: 42, Errors: 1.
please resove the issue.thanks in advance!!!
The error states that the routes.php file is missing in the folder config. Refer to the CakePHP 3 Documentation to create a meaningful routes.php.