B4J Question [Server] Working in Debug, not in Release

MathiasM

Active Member
Licensed User
Hello

My server app is running fine in debug mode, but not in release.
It's throwing an error on every request:

java.lang.RuntimeException: java.lang.RuntimeException: Method: _getinrequest not matched.

The request returns a 500 error message:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Error 500 java.lang.RuntimeException: java.lang.RuntimeException: Method: _getinrequest not matched.</title>
</head>
<body>
<h2>HTTP ERROR 500</h2>
<p>Problem accessing /session. Reason:
<pre> java.lang.RuntimeException: java.lang.RuntimeException: Method: _getinrequest not matched.</pre>
</p>
<hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.z-SNAPSHOT</a>
<hr />
</body>
</html>

The point is, I do have an "InRequest" method on a class, and I also have a module named InRequest, isn't that allowed?
 
Solution
Your code is simply wrong. Your are making wrong assumptions on the underlying implementation.

Correct code:
B4X:
If CallSub(u, "get" & filterKey) <> filterMap.Get(filterKey) Then

DonManfred

Expert
Licensed User
Longtime User
The point is that we can not help without knowing the full error. Even no code is shown. How could we help here?
 
Upvote 0

MathiasM

Active Member
Licensed User
Hello

Thanks for the replies you guys. Sorry that I didn't provide more information, it was 1:30 AM and was feeding my newborn, so I was a bit sleep deprived.
Now with a lot more context:

First, the full error message:
B4X:
2021-10-20 07:10:56.620:INFO::main: Logging initialized @598ms to org.eclipse.jetty.util.log.StdErrLog
2021-10-20 07:10:56.786:INFO:oejs.Server:main: jetty-9.4.z-SNAPSHOT; built: 2018-05-03T15:56:21.710Z; git: daa59876e6f384329b122929e70a80934569428c; jvm 11.0.1+13
2021-10-20 07:10:56.805:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
2021-10-20 07:10:56.805:INFO:oejs.session:main: No SessionScavenger set, using defaults
2021-10-20 07:10:56.809:INFO:oejs.session:main: node0 Scavenging every 660000ms
2021-10-20 07:10:56.814:INFO:oejsh.ContextHandler:main: Started o.e.j.s.ServletContextHandler@3e96bacf{/,file:///C:/Users/mathias.maes/Videos/Github/xxxxxxxxxxxxx_Controller/Objects/www/,AVAILABLE}
2021-10-20 07:10:56.818:INFO:oejs.AbstractNCSARequestLog:main: Opened C:\Users\mathias.maes\Videos\Github\xxxxxxxxxxxx_Controller\Objects\logs\b4j-2021_10_20.request.log
2021-10-20 07:10:56.841:INFO:oejs.AbstractConnector:main: Started ServerConnector@32ee1702{HTTP/1.1,[http/1.1]}{0.0.0.0:10601}
2021-10-20 07:10:56.844:INFO:oejs.Server:main: Started @821ms
java.lang.RuntimeException: java.lang.RuntimeException: Method: _getinrequest not matched.
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:137)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:95)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:130)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at anywheresoftware.b4j.object.JServlet$Handle.run(JServlet.java:135)
    at anywheresoftware.b4j.object.JServlet.Handle(JServlet.java:110)
    at anywheresoftware.b4j.object.JServlet.doFilter(JServlet.java:72)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1253)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
    at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1155)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:126)
    at org.eclipse.jetty.server.handler.gzip.GzipHandler.handle(GzipHandler.java:724)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
    at org.eclipse.jetty.server.Server.handle(Server.java:531)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:352)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:281)
    at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:102)
    at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:760)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:678)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: java.lang.RuntimeException: Method: _getinrequest not matched.
    at anywheresoftware.b4j.object.JavaObject.RunMethod(JavaObject.java:130)
    at b4j.example.endpointdefinition._getparameterdefinitionlist2(endpointdefinition.java:154)
    at b4j.example.endpointdefinition._getparameternames2(endpointdefinition.java:205)
    at b4j.example.checkqueryparameters._filter(checkqueryparameters.java:57)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:108)
    ... 52 more

I was able to track the problem down:

A bit of context, I have a quite large object (a lot of properties etc) called a "ParameterDefinition", multiple instances are stored in a list. I have written a function to filter out only the instances that have the property values I want. Filtering happens with a Map.

Simplified example:

Object ParameterDefinition
getName
getID


Now I have a function to which I can pass a Map this way:
FilterParameterDefinition(CreateMap("Name":"Test"))

Because my ParameterDefinition has a lot of properties (and it can and will grow in numbers), and I didn't want to write a myriad of IF statements to cover all properties.
So I turned to using RunMethod on a JavaObject of my ParameterDefinition, I loop over the Map, retrieve the _get & CurrentMapKey value and check if it is equal to the value of the Map

If all values are the same, the instance matches and is added to a list and then returned. This works perfectly in debug mode.

The function looks like this:

B4X:
Public Sub GetParameterDefinitionList2(optionMap As Map) As List
    Dim paramList As List
    paramList.Initialize
   
    For Each pd As ParameterDefinition In GetParameterDefinitionList
        Dim jo As JavaObject = pd
        Dim areAllOptionsRight As Boolean = True
        For Each optionKey As String In optionMap.Keys
            If jo.RunMethod("_get" & optionKey.ToLowerCase, Array As Object(pd)) <> optionMap.Get(optionKey) Then
                areAllOptionsRight = False
            End If
        Next
       
        If areAllOptionsRight Then paramList.Add(pd)
    Next
   
    Return paramList
End Sub


The problem seems to be that one method _getinrequest, which maps to (or at least should):
B4X:
Public Sub getInRequest As Byte
    Return mInRequest
End Sub

In my code I want all ParameterDefinitions which are body parameters and are mandatory. The code is called this way:

B4X:
GetParameterDefinitionList2(CreateMap("InRequest": InRequestTypes.Body, "Mandatory": True))

InRequestTypes is a module with a const with only 2 values:
B4X:
Sub Process_Globals
    Public Const Query=0, Body=1 As Byte
End Sub

I hope this all makes sense.

As said, the code has been working perfectly for months in debug mode. The odd thing is the error message for me: It's not "Method not found", but "Method not matched".
I have no idea what that means, and I have no idea why it only is an issue in release mode.

I did found out that passing something totally different than a byte in the map (eg: a string) produces the same error message. But why would a Byte be different in Debug mode than Release mode.

Thanks for any insights or help.
 
Upvote 0

MathiasM

Active Member
Licensed User
@Erel

I have created a minimal project to show the odd behaviour.
The project works in debug mode, but fails in release mode.
It's exactly the same as my main project, only diff is that it fails here on a Int value (the age of a user)

Is this a bug? Or is my runmethod code wrong in Release mode?
 

Attachments

  • Weird.zip
    38 KB · Views: 171
Upvote 0
Top