Skip to content

Commit

Permalink
GH-5148 fixes based on review
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad committed Oct 23, 2024
1 parent 34807e1 commit cad4af9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ private boolean isNamespaceData(byte[] data) {
private NativeValue data2value(int id, byte[] data) throws IOException {
if (data.length == 0) {
if (softFailOnCorruptData) {
return new CorruptValue(revision, id);
return new CorruptValue(revision, id, data);
}
throw new SailException("Empty data array for value with id " + id);
}
Expand All @@ -556,7 +556,7 @@ private NativeValue data2value(int id, byte[] data) throws IOException {
return data2literal(id, data);
default:
if (softFailOnCorruptData) {
return new CorruptValue(revision, id);
return new CorruptValue(revision, id, data);
}
throw new SailException("Invalid type " + data[0] + " for value with id " + id);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
/*******************************************************************************
* Copyright (c) 2024 Eclipse RDF4J contributors, Aduna, and others.
* Copyright (c) 2024 Eclipse RDF4J contributors.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Distribution License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: BSD-3-Clause
*******************************************************************************/
******************************************************************************/

package org.eclipse.rdf4j.sail.nativerdf.model;

import org.eclipse.rdf4j.sail.nativerdf.ValueStoreRevision;

/**
* CorruptValue is used when a NativeValue cannot be read from the ValueStore and if soft failure is enabled (see
* ValueStore#softFailOnCorruptData).
*
* <p>
* There is no method isCorruptValue() as it would exist for a "regular" implementation of NativeValue. Since
* CorruptValue is only to be used in exceptional situations, the recommended way of checking for it is using
* "instanceof".
Expand All @@ -24,32 +25,17 @@
*/
public class CorruptValue implements NativeValue {

/*-----------*
* Constants *
*-----------*/

private static final long serialVersionUID = 8829067881854394802L;

/*----------*
* Variables *
*----------*/

private final byte[] data;
private volatile ValueStoreRevision revision;

private volatile int internalID;

/*--------------*
* Constructors *
*--------------*/

public CorruptValue(ValueStoreRevision revision, int internalID) {
public CorruptValue(ValueStoreRevision revision, int internalID, byte[] data) {
setInternalID(internalID, revision);
this.data = data;
}

/*---------*
* Methods *
*---------*/

@Override
public void setInternalID(int internalID, ValueStoreRevision revision) {
this.internalID = internalID;
Expand All @@ -67,7 +53,17 @@ public int getInternalID() {
}

public String stringValue() {
return Integer.toString(internalID);
return "CorruptValue_with_ID_" + internalID;
}

/**
* Returns the bytes that were read from the ValueStore for this value's internalID. Since the value is corrupt the
* data may be null or an empty array.
*
* @return null, empty array or corrupt data
*/
public byte[] getData() {
return data;
}

@Override
Expand All @@ -88,4 +84,4 @@ public boolean equals(Object o) {
return super.equals(o);
}

}
}

0 comments on commit cad4af9

Please sign in to comment.