Why does the Swift interpreter provide memory locations for instances that throw runtime errors, but not class names? - swift

I am trying to debug my Swift application. Below is the error message that I am receiving.
In the image, it is clear that the interpreter knows where the instance of the class is. So why doesn't the error message provide a class name to go with the error in this case? Thank you!

It does. The full error has the form:
objc[9596]: -[main.Foo a_missing_method]: unrecognized selector sent to instance 0x7fa711505390 (no message forward handler is installed)
-[main.Foo a_missing_method] is telling you that the selector a_missing_method was being sent to an instance of class main.Foo (a method being sent to the class itself would use a + instead of a -).

Related

Kafka loading SASL callback handling class but not using it

I am trying to implement OAUTHBEARER as the SASL mechanism. Part of that is I need to override both the server and login callback handler classes. I am using docker and thus setting them via the environment variables:
KAFKA_LISTENER_NAME_OUTSIDE_OAUTHBEARER_SASL_SERVER_CALLBACK_HANDLER_CLASS=[class_name]
What is odd is that it clearly is loading the designated class as I am handily doing a log.warn("ctor...") in the constructor of said classes. But the stacktrace shows that it is not calling the handle method of the supplied class, but instead AbstractLogin$DefaultLoginHandler class:
[2021-11-23 17:41:57,137] WARN OAuthAuthenticateValidatorCallbackHandler - ctor: v1.1 (com.oauth2.security.oauthbearer.OAuthAuthenticateValidatorCallbackHandler) [2021-11-23 17:41:57,153] ERROR Unrecognized SASL Login callback (org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule) javax.security.auth.callback.UnsupportedCallbackException: Unrecognized SASL Login callback at org.apache.kafka.common.security.authenticator.AbstractLogin$DefaultLoginCallbackHandler.handle(AbstractLogin.java:105) at org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule.identifyToken(OAuthBearerLoginModule.java:316)
Is there any suggestions as to why it is loading the handler class but not using it? If I simply remove the environment variables for both LOGIN/SERVER_CALLBACK_HANDLER_CLASS, same Exception but without the WARN proving that the class was loaded. One possibility that I can't really reconcile with is that the stacktrace seems to refer to a LoginCallbackHandler but the class invoked is the Server/ValidatorCallbackHandler; as if it wasn't able to load the login callback handler and only the Validator callback handler, but I have double checked that a) the environment variables pertain to the correct class name (login==Login && server==Validator) and that the class names are indeed correct.
something happens when i post to stackoverflow and the answer magically reveals itself.
what i needed to do is also include SASL config for the other listener:
KAFKA_LISTENER_NAME_INSIDE_PLAIN_SASL_JAAS_CONFIG="org.apache..."
And then it works with both INSIDE://PLAIN and OUTSIDE://OAUTHBEARER.

mapbox-navigation-android-master error on demo application

I have try to run the mention demo application on mobile device. NavigationActivity. However after a while the application error and exit with error message below.
java.lang.NullPointerException: Attempt to invoke virtual method 'double com.mapbox.services.android.navigation.v5.MapboxNavigationOptions.getMinimumHighAlertDistance()' on a null object reference
anybody experience the same problem? any resolution?
Thanks.
When you have a class MyClass and you have a null object of that class like
MyClass myInstance = null;
and instances of MyClass have a method called myMethod(), then calling it like
myInstance.myMethod();
will result in NullPointerException if myInstance is null. To resolve your problem you need to do one of the following:
put the code into a try-catch and handle the exception in the catch
verify whether myInstance is null and if it is not, only then call its myMethod
make sure myInstance will not be null when you intend to use its methods/members

Getting a weird cast exception : javax.mail.session cannot be cast to javax.mail.session

I am trying to use apche-commons-email API for sending an email, in my java web application. I have configured the jboss5 mail-service.xml to send emails from Gmail id. But I am getting the error
org.jboss.resteasy.spi.UnhandledException: java.lang.ClassCastException:
javax.mail.Session cannot be cast to javax.mail.Session
when executing the line
Session mailSession = (Session) ictx.lookup("java:/Mail");
Please help.
I can only see this as a custom class loader loading a javax.mail.Session class along with the original javax.mail.Session object !
But when attempting to cast an object of the first class to an instance of the second, an exception occurs because both objects don't match (i.e. method names, member variables..etc)
Check this answer and other answers for the same question.

Dont understand the concept of extends in URL.openConnection() in JAVA

Hi I am trying to learn JAVA deeply and so I am digging into the JDK source code in the following lines:
URL url = new URL("http://www.google.com");
URLConnection tmpConn = url.openConnection();
I attached the source code and set the breakpoint at the second line and stepped into the code. I can see the code flow is: URL.openConnection() -> sun.net.www.protocol.http.Handler.openConnection()
I have two questions about this
First In URL.openConnection() the code is:
public URLConnection openConnection() throws java.io.IOException {
return handler.openConnection(this);
}
handler is an object of URLStreamHandler, define as blow
transient URLStreamHandler handler;
But URLStreamHandler is a abstract class and method openConnection() is not implement in it so when handler calls this method, it should go to find a subclass who implement this method, right? But there are a lot classes who implement this methods in sun.net.www.protocol (like http.Hanlder, ftp.Handler ) How should the code know which "openConnection" method it should call? In this example, this handler.openConnection() will go into http.Handler and it is correct. (if I set the url as ftp://www.google.com, it will go into ftp.Handler) I cannot understand the mechanism.
second. I have attached the source code so I can step into the JDK and see the variables but for many classes like sun.net.www.protocol.http.Handler, there are not source code in src.zip. I googled this class and there is source code online I can get but why they did not put it (and many other classes) in the src.zip? Where can I find a comprehensive version of source code?
Thanks!
First the easy part:
... I googled this class and there is source code online I can get but why they did not put it (and many other classes) in the src.zip?
Two reasons:
In the old days when the Java code base was proprietary, this was treated as secret-ish ... and not included in the src.zip. When they relicensed Java 6 under the GPL, they didn't bother to change this. (Don't know why. Ask Oracle.)
Because any code in the sun.* tree is officially "an implementation detail subject to change without notice". If they provided the code directly, it helps customers to ignore that advice. That could lead to more friction / bad press when customer code breaks as a result on an unannounced change to sun.* code.
Where can I find a comprehensive version of source code?
You can find it in the OpenJDK 6 / 7 / 8 repositories and associated download bundles:
http://hg.openjdk.java.net/jdk6/jdk6 - http://download.java.net/openjdk/jdk6/
http://hg.openjdk.java.net/jdk7/jdk7 - http://download.java.net/openjdk/jdk7/
http://hg.openjdk.java.net/jdk8/jdk8
Now for the part about "learning Java deeply".
First, I think you are probably going about this learning in a "suboptimal" fashion. Rather than reading the Java class library, I think you should be reading books on java and design patterns and writing code for yourself.
To the specifics:
But URLStreamHandler is a abstract class and method openConnection() is not implement in it so when handler calls this method, it should go to find a subclass who implement this method, right?
At the point that the handler calls than method, it is calling it on an instance of the subclass. So finding the right method is handled by the JVM ... just like any other polymorphic dispatch.
The tricky part is how you got the instance of the sun.net.www.protocol.* handler class. And that happens something like this:
When a URL object is created, it calls getURLStreamHandler(protocol) to obtain a handler instance.
The code for this method looks to see if the handler instance for the protocol already exists and returns that if it does.
Otherwise, it sees if a protocol handler factory exists, and if it does it uses that to create the handler instance. (The protocol handler factory object can be set by an application.)
Otherwise, searches a configurable list of Java packages to find a class whose FQN is package + "." + protocol + "." + "Handler", loads it, and uses reflection to create an instance. (Configuration is via a System property.)
The reference to handler is stored in the URL's handler field, and the URL construction continues.
So, later on, when you call openConnection() on the URL object, the method uses the Handler instance that is specific to the protocol of the URL to create the connection object.
The purpose of this complicated process is to support URL connections for an open-ended set of protocols, to allow applications to provide handlers for new protocols, and to substitute their own handlers for existing protocols, both statically and dynamically. (And the code is more complicated than I've described above because it has to cope with multiple threads.)
This is making use of a number of design patterns (Caches, Adapters, Factory Objects, and so on) together with Java specific stuff such as the system properties and reflection. But if you haven't read about and understood those design patterns, etcetera, you are unlikely to recognize them, and as a result you are likely to find the code totally bamboozling. Hence my advice above: learn the basics first!!
Take a look at URL.java. openConnection uses the URLStreamHandler that was previously set in the URL object itself.
The constructor calls getURLStreamHandler, which generates a class name dynamically and loads, and the instantiates, the appropriate class with the class loader.
But URLStreamHandler is a abstract class and method openConnection()
is not implement in it so when handler calls this method, it should go
to find a subclass who implement this method, right?
It has to be declared or abstract or implemented in URLStreamHandler. If you then give an instance of a class that extends URLStreamHandler with type URLStreamHandler and call the openConnection() method, it will call the one you have overriden in the instance of the class that extends URLStreamHandler if any, if none it will try to call the one in URLStreamHandler if implemented and else it will probably throw an exception or something.

Getting error while deploying code to production-->Previous load of class failed: qbdialer|insidesalessetup

I am facing an error conflict while deploying any code to the production.
Error is:
Previous load of class failed: qbdialer|insidesalessetup
qbDialer is a managed package.
Can anybody please help me to overcome from this issue?
Is your insidesalessetup class trying to call a method somewhere within qbdialers package? These errors tend to indicate you have a pre-existing class which has a reference to a method or class that no longer exists.
For example, if I created a class with a method Add(integer x, integer y, integer z), wrote a test method that called Add(1,2,3), then saved these they would both save okay. If I altered the method to just be Add(integer x, integer y) - removing the z parameter - I would get the error you are on about when I next ran my tests.
Paul