Skip to content

Commit

Permalink
Be defensive in NativeType.copy() methods: Act like createVariable() …
Browse files Browse the repository at this point in the history
…if no dataAccess is set
  • Loading branch information
tpietzsch committed May 7, 2024
1 parent 81a5018 commit 4b97c08
Show file tree
Hide file tree
Showing 23 changed files with 45 additions and 24 deletions.
5 changes: 4 additions & 1 deletion src/main/java/net/imglib2/type/label/BasePairBitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,10 @@ public BasePairBitType createVariable()
@Override
public BasePairBitType copy()
{
return new BasePairBitType( this.get() );
if ( dataAccess != null )
return new BasePairBitType( this.get() );
else
return createVariable();
}

@Override
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/net/imglib2/type/label/BasePairCharType.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,10 @@ public BasePairCharType createVariable()
@Override
public BasePairCharType copy()
{
return new BasePairCharType( get() );
if ( dataAccess != null )
return new BasePairCharType( get() );
else
return createVariable();
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/type/logic/BitType.java
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public BitType createVariable()
@Override
public BitType copy()
{
return new BitType( get() );
return new BitType( dataAccess != null ? get() : false );
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/type/logic/NativeBoolType.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public NativeBoolType createVariable()
@Override
public NativeBoolType copy()
{
return new NativeBoolType( get() );
return new NativeBoolType( dataAccess != null ? get() : false );
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/type/numeric/ARGBType.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public ARGBType createVariable()
@Override
public ARGBType copy()
{
return new ARGBType( get() );
return new ARGBType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,10 @@ public NativeARGBDoubleType createVariable()
@Override
public NativeARGBDoubleType copy()
{
return new NativeARGBDoubleType( getA(), getR(), getG(), getB() );
if ( dataAccess != null )
return new NativeARGBDoubleType( getA(), getR(), getG(), getB() );
else
return createVariable();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ public ComplexDoubleType createVariable()
@Override
public ComplexDoubleType copy()
{
return new ComplexDoubleType( getRealFloat(), getImaginaryFloat() );
if ( dataAccess != null )
return new ComplexDoubleType( getRealFloat(), getImaginaryFloat() );
else
return createVariable();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,10 @@ public ComplexFloatType createVariable()
@Override
public ComplexFloatType copy()
{
return new ComplexFloatType( getRealFloat(), getImaginaryFloat() );
if ( dataAccess != null )
return new ComplexFloatType( getRealFloat(), getImaginaryFloat() );
else
return createVariable();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ public ByteType createVariable()
@Override
public ByteType copy()
{
return new ByteType( getByte() );
return new ByteType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ public IntType createVariable()
@Override
public IntType copy()
{
return new IntType( getInt() );
return new IntType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,6 @@ public LongType createVariable()
@Override
public LongType copy()
{
return new LongType( get() );
return new LongType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ public ShortType createVariable()
@Override
public ShortType copy()
{
return new ShortType( getShort() );
return new ShortType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,11 @@ public Unsigned128BitType createVariable()
public Unsigned128BitType copy()
{
final Unsigned128BitType copy = new Unsigned128BitType();
final int k = i.get() * 2;
copy.set( dataAccess.getValue( k ), dataAccess.getValue( k + 1 ) );
if ( dataAccess != null )
{
final int k = i.get() * 2;
copy.set( dataAccess.getValue( k ), dataAccess.getValue( k + 1 ) );
}
return copy;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,6 @@ public Unsigned12BitType createVariable()
@Override
public Unsigned12BitType copy()
{
return new Unsigned12BitType( get() );
return new Unsigned12BitType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,6 @@ public Unsigned2BitType createVariable()
@Override
public Unsigned2BitType copy()
{
return new Unsigned2BitType( get() );
return new Unsigned2BitType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,6 @@ public Unsigned4BitType createVariable()
@Override
public Unsigned4BitType copy()
{
return new Unsigned4BitType( get() );
return new Unsigned4BitType( dataAccess != null ? get() : 0 );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public UnsignedByteType createVariable()
@Override
public UnsignedByteType copy()
{
return new UnsignedByteType( get() );
return new UnsignedByteType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public UnsignedIntType createVariable()
@Override
public UnsignedIntType copy()
{
return new UnsignedIntType( get() );
return new UnsignedIntType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ public UnsignedLongType createVariable()
@Override
public UnsignedLongType copy()
{
return new UnsignedLongType( get() );
return new UnsignedLongType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public UnsignedShortType createVariable()
@Override
public UnsignedShortType copy()
{
return new UnsignedShortType( get() );
return new UnsignedShortType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ public UnsignedVariableBitLengthType createVariable()
@Override
public UnsignedVariableBitLengthType copy()
{
return new UnsignedVariableBitLengthType( getBits(), nBits );
if ( dataAccess != null )
return new UnsignedVariableBitLengthType( getBits(), nBits );
else
return createVariable();
}

/** @see UnsignedLongType#divide(long, long) */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public DoubleType createVariable()
@Override
public DoubleType copy()
{
return new DoubleType( get() );
return new DoubleType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imglib2/type/numeric/real/FloatType.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public FloatType createVariable()
@Override
public FloatType copy()
{
return new FloatType( get() );
return new FloatType( dataAccess != null ? get() : 0 );
}

@Override
Expand Down

0 comments on commit 4b97c08

Please sign in to comment.