Skip to content

Commit

Permalink
Ensure NullNode, MissingNode remain singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Aug 28, 2019
1 parent ae2d369 commit bc59123
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,22 @@
public final class MissingNode
extends ValueNode
{
private static final long serialVersionUID = 1L;

private final static MissingNode instance = new MissingNode();

/**
*<p>
* NOTE: visibility raised to `protected` in 2.9.3 to allow custom subtypes.
* NOTE: visibility raised to `protected` in 2.9.3 to allow custom subtypes
* (which may not be greatest idea ever to have but was requested)
*/
protected MissingNode() { }

// To support JDK serialization, recovery of Singleton instance
protected Object readResolve() {
return instance;
}

@Override
public boolean isMissingNode() {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public final class NullNode
{
// // Just need a fly-weight singleton

private static final long serialVersionUID = 1L;

public final static NullNode instance = new NullNode();

/**
Expand All @@ -23,6 +25,11 @@ public final class NullNode
*/
protected NullNode() { }

// To support JDK serialization, recovery of Singleton instance
protected Object readResolve() {
return instance;
}

public static NullNode getInstance() { return instance; }

@Override
Expand Down

0 comments on commit bc59123

Please sign in to comment.