Skip to content
Snippets Groups Projects
Commit 18195307 authored by gwen-soleil's avatar gwen-soleil
Browse files

Avoid NPE (Jira TANGOARCH-743)

parent a143ca61
Branches
No related tags found
No related merge requests found
package fr.soleil.archiving.snap.api.persistence;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.TangoDs.TangoConst;
......@@ -21,6 +16,10 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.ScStr1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.ScStr2Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp2Val;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
public class SpringSnapshotPersistenceManagerImpl implements SnapshotPersistenceManager {
private final Logger logger = LoggerFactory.getLogger(SpringSnapshotPersistenceManagerImpl.class);
......@@ -33,8 +32,7 @@ public class SpringSnapshotPersistenceManagerImpl implements SnapshotPersistence
@Override
public void store(final AnyAttribute attribute, final PersistenceContext persistenceContext) throws Exception {
final SnapshotPersistenceContext context = (SnapshotPersistenceContext) persistenceContext;
logger.debug(attribute.getCompleteName() + " - values: "
+ Arrays.toString(attribute.getConvertedStringValuesTable()));
logger.debug("storing {} with value: {}", attribute.getCompleteName(), Arrays.toString(attribute.getConvertedStringValuesTable()));
switch (attribute.getFormat()) {
case AttrDataFormat._SCALAR:
if (attribute.getWritable() == AttrWriteType._READ) {
......
......@@ -37,14 +37,18 @@ public class ScNum1Val extends Val {
public ScNum1Val(AnyAttribute attribute, SnapshotPersistenceContext context) {
super(attribute, context);
double[] val = attribute.getConvertedNumericValuesTable();
this.value = val[0];
if (val == null) {
value = Double.NaN;
} else {
value = val[0];
}
}
/**
* @return the value
*/
public double getValue() {
return this.value;
return value;
}
/**
......
......@@ -43,8 +43,13 @@ public class ScNum2Val extends Val {
super(attribute, context);
double[] val = attribute.getConvertedNumericValuesTable();
this.readValue = val[0];
this.writeValue = val[1];
if (val == null) {
readValue = Double.NaN;
writeValue= Double.NaN;
} else {
readValue = val[0];
writeValue = val[1];
}
}
/**
......
......@@ -36,21 +36,23 @@ public class ScStr1Val extends Val {
public ScStr1Val(AnyAttribute attribute, SnapshotPersistenceContext context) {
super(attribute, context);
String[] val = attribute.getConvertedStringValuesTable();
this.value = val[0];
if (val == null) {
value = null;
} else {
value = val[0];
}
}
/**
* @return the value
*/
public String getValue() {
return this.value;
return value;
}
/**
* @param value
* the value to set
* @param value the value to set
*/
public void setValue(String value) {
this.value = value;
......
......@@ -39,9 +39,14 @@ public class ScStr2Val extends Val {
super(attribute, context);
String[] val = attribute.getConvertedStringValuesTable();
if (val == null) {
readValue = null;
writeValue= null;
} else {
this.readValue = val[0];
this.writeValue = val[1];
}
}
/**
* @return the readValue
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment