DestinationSol: java.lang.NullPointerException: ... because "environment" is null

What you were trying to do

I was trying to run the game as follows:

nix-shell
./gradlew
./gradlew run

What actually happened

java.lang.NullPointerException: Cannot invoke "org.terasology.gestalt.module.ModuleEnvironment.getSubtypesOf(java.lang.Class, java.util.function.Predicate)" because "environment" is null
...

How to reproduce

No response

Game version

2.1.0 (develop branch)

Log details

java.lang.NullPointerException: Cannot invoke "org.terasology.gestalt.module.ModuleEnvironment.getSubtypesOf(java.lang.Class, java.util.function.Predicate)" because "environment" is null
	at org.terasology.gestalt.entitysystem.component.management.ComponentTypeIndex.changeEnvironment(ComponentTypeIndex.java:84)
	at org.terasology.gestalt.entitysystem.component.management.ComponentTypeIndex.<init>(ComponentTypeIndex.java:67)
	at org.destinationsol.assets.AssetHelper.init(AssetHelper.java:82)
	at org.destinationsol.SolApplication.create(SolApplication.java:164)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.initializeListener(Lwjgl3Window.java:416)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:366)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:193)
	at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:167)
	at org.destinationsol.desktop.SolDesktop.main(SolDesktop.java:138)

Operating System

Linux

Additional Info

I use NixOS.

Here is the shell.nix where I usually run DS:

let
  nixpkgs = fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-unstable";
  pkgs = import nixpkgs { config = {}; overlays = []; };
in

pkgs.mkShell {
  packages = with pkgs; [
#    git # already installed
#    temurin-bin-11 # I installed temurin-bin-21 instead
    libglvnd
    libpulseaudio
    xorg.libXcursor
    xorg.libXrandr
    xorg.libXxf86vm
  ];
  LD_LIBRARY_PATH = "${pkgs.stdenv.cc.cc.lib}/lib:${pkgs.libglvnd}/lib:${pkgs.libpulseaudio}/lib:${pkgs.xorg.libXcursor}/lib:${pkgs.xorg.libXrandr}/lib:${pkgs.xorg.libXxf86vm}/lib";
}

I was able to run the game exactly as I tried today. It’s a fresh clone, no changes, just the source code as it is in this repository; however, it didn’t work this time.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

The changes in https://github.com/BenjaminAmos/DestinationSol/commit/fdeced3758f69f7e085a51dd103e4a87a4984409 should work. We are unable to use the Runtime class yet because the code is still compiled against Java 8 for Android runtime compatibility. This means that we are limited to the APIs available in Java 8, even if the game is unable to actually run on Java 8 anymore.

java.lang.UnsupportedOperationException: The Security Manager is deprecated and will be removed in a future release
       at java.base/java.lang.System.setSecurityManager(System.java:425)
       at org.destinationsol.modules.ModuleManager.loadEnvironment(ModuleManager.java:281)
       at org.destinationsol.modules.ModuleManager.init(ModuleManager.java:248)
       at org.destinationsol.SolApplication.create(SolApplication.java:158)
       at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.initializeListener(Lwjgl3Window.java:416)
       at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Window.update(Lwjgl3Window.java:366)
       at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.loop(Lwjgl3Application.java:193)
       at com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application.<init>(Lwjgl3Application.java:167)
       at org.destinationsol.desktop.SolDesktop.main(SolDesktop.java:138)

This error is likely the cause. It’s a known issue and usually happens with Java versions above 17. The exception is thrown because SecurityManager is deprecated for removal. Since the game typically runs with Java 11 this is not usually encountered.

A workaround is something along the lines of the following in ModuleManager, which I will try and add soon:

if (Runtime.version().feature() < 18 || "allow".equals(System.getProperty("java.security.manager"))) {
    Policy.setPolicy(new ModuleSecurityPolicy());
    System.setSecurityManager(new ModuleSecurityManager());
} else {
    logger.warn("SecurityManager is disabled starting with Java 18 - module sandbox functionality is limited!");
    logger.warn("To enable SecurityManager, use the \"-Djava.security.manager=allow\" JVM option.");
}

Although with that nix-shell environment you should be using Java 11 already. What output do you see from running the java -version command in that shell?