Oops Null Pointer

Java programming related

Category Archives: Uncategorized

Minecraft Modding: A Template Mod

My son loves playing Minecraft mods and wanted to make his own. He had a plethora of grand ideas. I advised to start small to create something achievable. And thus the Sandwich Mod (GitHub link) was created. It adds a piece of bread and a slice of cheese, which can be crafted into a cheese sandwich.

I couldn’t find any quick start mod samples for Minecraft 1.11, but I did find a reasonably straight-forward and detailed video tutorial series by CJMinecraft. From the ideas there I created a simple mod that adds 3 new edible items and a recipe.

To get started you need

  • The Java 1.8 JDK installed
  • A Java IDE (Eclipse or Intellj)
  • git to check out the code
  • A copy of Minecraft

The mod is based on Mincraft Forge, which provides a bunch of hooks to get started. I use Gradle as a build tool as it downloads all the dependencies you need and compiles and packages the mod.

Forge also provides a launcher so you can start Minecraft from your IDE with you mod installed to play-test or debug.

Check out the readme file on GitHub for all the instructions and let me know if you get stuck.


Logging aggregation and filtering for humans and machines

Some thoughts around better approaches logging have been coalescing after reading a few articles. With the filtering power of log aggregation and processing tools in mind like ELK stack, this article challenging the assumption that logs are for only for humans was interesting. I still think human readable logs can be important, so maybe a logging tool can configured to dump both a formatted string and a JSON detailed log into different log targets. Maybe a good log aggregator means there is no need to look elsewhere.

The idea of logs as the central source of data in distributed systems in intriguing. I found Jay Kreps’ article on the subject enlightening.

Finding the right granularity for the format is also an interesting problem. I have been working with a monitoring system that used the Common Base Event format mapped into a database table. The format (more specifically the current implementation) was not ideal for the way we use the system and is a source of performance issues, but is entrenched in the applications of the enterprise. A JSON based version stored in a document database and feed into ELK would be a much better fit.

Eclipse Luna with Google plugin requires JDK 7

I installed the google plugin (4.4) for eclipse luna but no google icons appeared in the toolbar and no options for google were in the preferences.

Looking at the log file in workspace/.metatdata/ .log it reports that JDK 7 is required.

I added -vm {path to jdk7} and all is good.

To use an old GWT version before 2.5 you will need a gwt-codeserver.jar file in the GWT directory to fool the plugin (found the hint here)

Gerkin evaluation engine

An workmate from a previous job posted this article discussing the release of a Gerkin (Given-When-Then) evaluation engine. Interesting idea. I figure that JBehave has a built in interpreter and maybe this could be leveraged for that project to switch from JBehave to another testing framework at will.

Creating UML Sequence Diagrams from Debug / Stack traces

I found a good tool to create sequence / class interaction diagrams from Java stack traces or debug stacks using a free Eclipse plugin called AmaterasUML. Install it in Eclipse and you can open a “Sequence diagram from stacktrace” view, paste in a stacktrace and it will generate a nice looking sequence diagram.

With a bit of text manipulation you can modify a debug trace (from right-click “Copy Stack” on the debug window) to look like a stack trace and generate the UML from a debug breakpoint. The steps are:

  • Add “at ” to the start of every line
  • Replace method args with the class name.java:line number
  • Clean up $2$1 type class suffixes


EventRegistryImpl.fireEvent(Event) line: 47
BaseFolderNavigator$2.handleEvent(Event) line: 79
CoverageNavigatorViewGXT(BaseObservable).fireEvent(Event) line: 27
BaseNavigatorViewGXT$2$1.execute() line: 149


at EventRegistryImpl.fireEvent(EventRegistryImpl.java:47)
at BaseFolderNavigator.handleEvent(BaseFolderNavigator.java:79)
at CoverageNavigatorViewGXT(BaseObservable).fireEvent(CoverageNavigatorViewGXT.java:27)
at BaseNavigatorViewGXT.execute(BaseNavigatorViewGXT.java:149)

Below is a gawk command (via UnxUtils) to convert a stack file (x.txt) to a stacktrace

gawk "{str = $0; sub(/^\t/, \"^\", str);match(str, /(.*)\./, arr); sub(/^/, \"^at \", str);sub(/\(.*\./,\".\",str);sub(/\([^\)]*\)/, \"(\", str);sub(/ line: /, arr[1]\".java:\", str);sub(/$/, \")\", str);sub(/\t\)$/, \"\)\", str);print str}" x.txt

Dependency Injection to avoid circular dependencies

Dependencies injection saves the day again, this time in helping work around a circular dependency.

Often you have to work with legacy code that can not be changed easily. In my case I had a project called Gateway (containing a JSON Gateway) that depends on a project called Common. I needed an instance of a class in Gateway to be used in the Common package. Common has no visibility of classes in Gateway. It would create a circular dependency if Gateway was changed to depended on Common.

Keep in mind that major restructuring was not an option due to legacy code and time constraints. There are some bigger issues that are causing the problem, but I needed a simple solution for now.

To solve this problem, I made an interface in Common and changed the class in Gateway to implement that interface. As Gateway depends on Common, this is bearable. I then wired the class in Gateway into where it was needed in Common at runtime with spring using the newly created interface.

Works a treat.