Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.97a is out! (02/02/24); New blog post: Simulator Enhancements (03/13/24)

Author Topic: Memory leak: Final value who become null?  (Read 3949 times)

Snrasha

  • Admiral
  • *****
  • Posts: 705
    • View Profile
Memory leak: Final value who become null?
« on: November 21, 2017, 12:15:04 PM »

Today, i have received about a player that:

Code
2249965 [Thread-4] ERROR com.fs.starfarer.combat.CombatMain  - java.lang.NullPointerException
java.lang.NullPointerException
    at src.lt.data.scripts.campaign.Lt_SpecialCampaignFleetAI.pickLootersLocation(Lt_SpecialCampaignFleetAI.java:70)
    at src.lt.data.scripts.campaign.Lt_SpecialCampaignFleetAI.run(Lt_SpecialCampaignFleetAI.java:50)
    at com.fs.starfarer.campaign.ai.AssignmentModule.advance(Unknown Source)
    at com.fs.starfarer.campaign.ai.ModularFleetAI.advance(Unknown Source)
    at com.fs.starfarer.campaign.fleet.CampaignFleet.advance(Unknown Source)
    at com.fs.starfarer.campaign.BaseLocation.advance(Unknown Source)
    at com.fs.starfarer.campaign.StarSystem.advance(Unknown Source)
    at com.fs.starfarer.campaign.CampaignEngine.advance(Unknown Source)
    at com.fs.starfarer.campaign.CampaignState.advance(Unknown Source)
    at com.fs.starfarer.BaseGameState.traverse(Unknown Source)
    at com.fs.state.AppDriver.begin(Unknown Source)
    at com.fs.starfarer.combat.CombatMain.main(Unknown Source)
    at com.fs.starfarer.StarfarerLauncher$1.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
About my mod.
-This is about a Private Final array list initialized on the constructor. (No-static)

The guy have say about the list of mod:
Quote
I use most/all faction mods including valkyre and approlight wich are translated chinese mods for teh latest version
No idea if too many mods can cause to destroy a final list, but after a unknow amount of time, it seems,
My array list become null. Then crash. I have fix that very without problem, but i have not put a case where he can be null, because he cannot, but meh, any things can happens, no? ^^

I want just to be sure if this a normal case of a "private final" without static, after a certain amount of time, because i have not found the problem on google and than this is technically a bug who can happens for others peoples, i put that here.


Logged
I am pretty bad on english. So, sorry in advance.

Gladiator Society
Add battle options on Com Relay/ Framework for modders for add their own bounty.

Sanguinary Autonomist Defectors A fan-mod of Shadowyard.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #1 on: November 21, 2017, 12:20:59 PM »

What you're describing is pretty much not possible. I suspect either the line number is wrong (maybe the script you're looking at is different than what the player is using?) or maybe it's your interpretation of what's on that line, but a "final" (or any other variable) is not just going to get set to null after some time unless something specifically sets it to null.
Logged

Snrasha

  • Admiral
  • *****
  • Posts: 705
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #2 on: November 21, 2017, 12:46:32 PM »

What you're describing is pretty much not possible. I suspect either the line number is wrong (maybe the script you're looking at is different than what the player is using?) or maybe it's your interpretation of what's on that line, but a "final" (or any other variable) is not just going to get set to null after some time unless something specifically sets it to null.
No, good file :x(and he is using the same version than me, previously)
Quote
  public final ArrayList<SectorEntityToken> lootersplanets;  // The final have be removed for the fix
    private final CampaignFleetAPI fleet;
    private SectorEntityToken hideoutLocation;

    public Lt_SpecialCampaignFleetAI(CampaignFleetAPI fleet) {
        this.fleet = fleet;
        this.lootersplanets = new ArrayList<>();
    }

    private void pickLootersLocation() {

        if(this.lootersplanets==null){   // Code added for fix the problem
            this.lootersplanets = new ArrayList<>();
        }

        if (this.lootersplanets.isEmpty()) {   // Where the crash happens, null exception here.
            generateQueue();
        }
        if (this.lootersplanets.isEmpty()) {
            return;
        }
[...]
After have made the fix, the player have not problem for playing anymore.
And, no, i never put him to Null:  (The second new is after than i have checked if this is null or not)


The public attribute is a "typos" error, i have put private, now. But it is not called anyways per a other class.

« Last Edit: November 21, 2017, 01:02:31 PM by Snrasha »
Logged
I am pretty bad on english. So, sorry in advance.

Gladiator Society
Add battle options on Com Relay/ Framework for modders for add their own bounty.

Sanguinary Autonomist Defectors A fan-mod of Shadowyard.

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #3 on: November 21, 2017, 01:03:00 PM »

I see what you're saying, but it's still not possible for that to happen the way you're describing.

One thing that's a remote possibility is if the game is saved, the savefile is edited to remove the lootersplanet list, and the game is reloaded. The constructor is only called when the object is first created, not when it's extracted from a savefile, so it's a possible way in which this "final" variable might get set to null.

But that's a long shot. My guess is still the NPE happening somewhere other than where you think, maybe due to a line number inconsistency/misreporting/etc. That seems *far* more likely than a final getting set to null for some random reason, that would be an *insane* bug in the JVM, and in my experience anything that looks like that just means one is missing something on their end.

It's also possible that the NPE doesn't happen reliably and that your fix didn't actually fix it.
Logged

Snrasha

  • Admiral
  • *****
  • Posts: 705
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #4 on: November 21, 2017, 01:09:59 PM »

I see what you're saying, but it's still not possible for that to happen the way you're describing.

One thing that's a remote possibility is if the game is saved, the savefile is edited to remove the lootersplanet list, and the game is reloaded. The constructor is only called when the object is first created, not when it's extracted from a savefile, so it's a possible way in which this "final" variable might get set to null.

But that's a long shot. My guess is still the NPE happening somewhere other than where you think, maybe due to a line number inconsistency/misreporting/etc. That seems *far* more likely than a final getting set to null for some random reason, that would be an *insane* bug in the JVM, and in my experience anything that looks like that just means one is missing something on their end.

It's also possible that the NPE doesn't happen reliably and that your fix didn't actually fix it.
Ok, thank you for your help. The memory leak with a incredible amount of mods have be so credible for me, but meh, i go probably wrong for that, i will see on a week/month if this bug reappears. (Like i have others private final who can have this problem also.)
Logged
I am pretty bad on english. So, sorry in advance.

Gladiator Society
Add battle options on Com Relay/ Framework for modders for add their own bounty.

Sanguinary Autonomist Defectors A fan-mod of Shadowyard.

zaimoni

  • Commander
  • ***
  • Posts: 110
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #5 on: November 21, 2017, 03:33:46 PM »

One thing that's a remote possibility is if the game is saved, the savefile is edited to remove the lootersplanet list, and the game is reloaded. The constructor is only called when the object is first created, not when it's extracted from a savefile, so it's a possible way in which this "final" variable might get set to null.
I've seen similar issues in Microsoft's C#'s serialization library support (usually where an undocumented language restriction activates).  Given what's pinning StarSector to Java 7 (the build process for Java itself), it's not unthinkable that an x-factor breaks down and the array simply doesn't get saved in a readable fashion.

And yes, the C# analog gives a garbage location on the error about one time in three.  This location was good enough to give a workaround, at least.
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #6 on: November 29, 2017, 05:04:10 AM »

Show us the full class file (ideally the exact same version as the one reported to contain the bug)

Also, are you distributing this class compiled, or using SS's Janino to compile it?
Janino's bytecode generation might be the source of the problem.

A wild stab in the dark:

- Janino is creating a hidden no-args constructor (perhaps because of a field being final). Ordinarily this wouldn't be an issue, but....
- Gson (the serialisation API used by SS) detects this constructor, and uses it, resulting in the object not correctly deserialising.

Though I suppose it that were the case, you'd be able to reproduce the bug yourself?
Logged

Alex

  • Administrator
  • Admiral
  • *****
  • Posts: 23987
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #7 on: November 29, 2017, 08:02:27 AM »

- Gson (the serialisation API used by SS) detects this constructor, and uses it, resulting in the object not correctly deserialising.

Starsector uses xstream...

My understanding is that constructors, default or otherwise, are not invoked by xstream on deserialization. Interesting guess, though - but what *is* invoked is a readResolve() method, if one exists, so that might be something to look at.
Logged

TJJ

  • Admiral
  • *****
  • Posts: 1905
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #8 on: November 29, 2017, 05:02:15 PM »

- Gson (the serialisation API used by SS) detects this constructor, and uses it, resulting in the object not correctly deserialising.

Starsector uses xstream...

Oh my bad, I misremembered; must have been my code that used gson then :)
« Last Edit: November 30, 2017, 06:36:03 AM by TJJ »
Logged

Snrasha

  • Admiral
  • *****
  • Posts: 705
    • View Profile
Re: Memory leak: Final value who become null?
« Reply #9 on: November 29, 2017, 11:10:51 PM »

TJJ, i do not use Janino ^^


Logged
I am pretty bad on english. So, sorry in advance.

Gladiator Society
Add battle options on Com Relay/ Framework for modders for add their own bounty.

Sanguinary Autonomist Defectors A fan-mod of Shadowyard.