Skip to main content

Troubleshooting Common Java Exceptions

Troubleshooting Common Java Exceptions

  • Below is an example of NullPointer Exception
     Exception in thread "main" java.lang.NullPointerException
      at com.example.myproject.Object1.getValue(Object1.java:16)
      at com.example.myproject.Object2.getNumericValue(Object2.java:25)
      at com.example.myproject.Object3.main(Object3.java:14)
    
    • In this case we need to navigate to the file Object1 and review the method called getValue() to determine what happened
    • The remaining lines give the further information about how the exception was arrived at.
  • Most of the times we'll have something different to the above, but the above given can be taken as a basic example of how to find out the issue.
  • Let us look at the below log once
     Exception in thread "main" java.lang.NullPointerException
      at com.example.myproject.Object1.getValue(Object1.java:16)
      at com.example.myproject.Object2.getNumericValue(Object2.java:25)
      at com.example.myproject.Object3.main(Object3.java:14)
     Caused by: java.lang.IllegalReferenceException
      at com.example.myproject.Object1.getParentValue(Object1.java:22)
    
    • This means that we have a NullPointer exception in Object1 at the getValue() method occured as Object1 and getParentValue() method thrown a IllegalReferenceException and this is the initial cause of the problem.
    • If we have multiple Caused by sections then the lowest is the initial cause of the problem.

Comments

Popular posts from this blog

Troubleshooting Tomcat using Catalina log

Troubleshooting Tomcat using Catalina log We can get the  catalina  logs in  $CATALINA_HOME/logs Here we'll have a  catalina.out We can see some huge info in that log file. If we want to what exactly happens since the start of tomcat then we need to log that into a new file. By default we have log rotation enabled on this logs. For now let us stop tomcat and nullify the catalina.out file and then start tomcat to have some new info in the catalina.out # service tomcat stop # cd $CATALINA_HOME/logs # :> catalina.out (or) cat /dev/null > catalina.out # ll catalina.out -rw-r----- 1 root root 0 Feb 18 16:19 catalina.out # service tomcat start # ll catalina.out -rw-r----- 1 root root 17341 Feb 18 16:21 catalina.out We can see the log being written after the start of tomcat. Now we can notice the instance giving some information about the starting of tomcat, about the configuration for the startup, path of the servlet instance for which the log is re...

Managing tomcat application

Tomcat is a servlet application which is ready to use after download. There is no need of installing this application. We can directly start or stop it from the bin directory.  So in such case we should go to the bin directory in the CATALINA_HOME or else we need to use the startup script along with its absolute path. And the same is needed to shut it down. We can use the below script to manage the tomcat application and we neither need to go to the CATALINA_HOME nor to use the absolute path. All we need to do is to change the permissions to make it executable and copy that to /sbin and /etc/init.d/ directories. If we copy this into /etc/init.d/ then also we need to mention the absolute path but we can easily memorize it as we know all the startup scripts exists there. But if we copy that into /sbin then there is absolutely no need of mentioning the path of the file. We can use this like below: # tomcat start|stop|restart|status #!/bin/bash # Author : Arjun S...

IPC (Incident, Problem & Change) Management with OTRS

IPC (Incident, Problem & Change) Management with OTRS 1.  Install OTRS 5 on CentOS 7 Download https://www.otrs.com/download-open-source-help-desk-software-otrs-free/ # rpm -i otrs-5.0.22-01.noarch.rpm Open  following link in browser to run the installer.  Replace  “otrs.itgratis.com” with your server IP/Hostname http:// otrs.itgratis.com /otrs/installer.pl Follow the instruction on the screen. You will find below screen for Database. Select  MySQL and click Next Here you need to Install MySQL-Community-Server before you click on Next. You can install Database on the same server or a separate server. Download https://dev.mysql.com/downloads/repo/yum/ Add MySQL Yum Repository # rpm -Uvh mysql57-community-release-el7-11.noarch.rpm Verifying MySQL Repo # yum repolist Install & Start MySQL Server #yum install mysql-community-server #systemctl start mysqld.service Find unamename & Password # grep 'temporary password...