Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/software/amazon/ion/EmptySymbolException.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
/**
* An error caused by a symbol not containing at least one character for
* its text.
*
* @deprecated this exception is not used as empty symbols are valid. In cases where null is used as the symbol value it was
* replaced by {@link NullPointerException}
*/
@Deprecated
public class EmptySymbolException
extends IonException
{
Expand Down
5 changes: 1 addition & 4 deletions src/software/amazon/ion/IonSymbol.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,8 @@ public String stringValue()
* @param value the new value of this symbol;
* may be <code>null</code> to make this <code>null.symbol</code>.
*
* @throws EmptySymbolException if <code>value</code> is the empty string.
*/
public void setValue(String value)
throws EmptySymbolException;

public void setValue(String value);

public IonSymbol clone()
throws UnknownSymbolException;
Expand Down
5 changes: 1 addition & 4 deletions src/software/amazon/ion/IonText.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,8 @@ public interface IonText
* @param value the new value of this text value;
* may be <code>null</code> to make this an Ion null value.
*
* @throws EmptySymbolException if this is an {@link IonSymbol} and
* <code>value</code> is the empty string.
*/
public void setValue(String value)
throws EmptySymbolException;
public void setValue(String value);

public IonText clone()
throws UnknownSymbolException;
Expand Down
3 changes: 1 addition & 2 deletions src/software/amazon/ion/IonValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,7 @@ public interface IonValue
* @param annotations the new annotations. If null or empty array, then
* all annotations are removed. Any duplicates are preserved.
*
* @throws EmptySymbolException if any of the annotations are null or
* empty string.
* @throws NullPointerException if any of the annotations are null
*
*/
public void setTypeAnnotations(String... annotations);
Expand Down
1 change: 0 additions & 1 deletion src/software/amazon/ion/IonWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public interface IonWriter
* @throws IllegalStateException if the current container isn't a struct,
* that is, if {@link #isInStruct()} is false.
* @throws NullPointerException if {@code name} is null.
* @throws EmptySymbolException if {@code name} is empty.
*/
public void setFieldName(String name);

Expand Down
1 change: 0 additions & 1 deletion src/software/amazon/ion/SymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ public interface SymbolTable
* {@link #UNKNOWN_SYMBOL_ID} if it's not defined.
*
* @throws NullPointerException if {@code name} is null.
* @throws EmptySymbolException if {@code name} is empty.
*/
public int findSymbol(String name);

Expand Down
2 changes: 1 addition & 1 deletion src/software/amazon/ion/ValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ public IonSexp newSexp(IonValue... children)
* @param value the text of the symbol;
* may be <code>null</code> to make <code>null.symbol</code>.
*
* @throws EmptySymbolException if <code>value</code> is the empty string.
* @throws NullPointerException if <code>value</code> is null.
*/
public IonSymbol newSymbol(String value);

Expand Down
14 changes: 3 additions & 11 deletions src/software/amazon/ion/impl/IonReaderTextRawX.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,13 +417,8 @@ private final void current_value_is_bool(boolean value)
}

private final void set_fieldname(SymbolToken sym) {
String text = sym.getText();
int sid = sym.getSid();
if (text != null && text.length() < 1) {
parse_error("empty strings are not valid field names");
}
_field_name = text;
_field_name_sid = sid;
_field_name = sym.getText();
_field_name_sid = sym.getSid();
}

private final void clear_fieldname() {
Expand Down Expand Up @@ -877,10 +872,7 @@ protected final void parse_to_next_value() throws IOException
case ACTION_LOAD_ANNOTATION:
{
sb = token_contents_load(t);
if (sb.length() < 1) {
// this is the case for an empty symbol
parse_error("empty symbols are not valid");
}

trailing_whitespace = _scanner.skip_whitespace();
if (!_scanner.skipDoubleColon()) {
// unnecessary: set_current_value(sp);
Expand Down
10 changes: 3 additions & 7 deletions src/software/amazon/ion/impl/IonWriterSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static software.amazon.ion.impl.PrivateUtils.newSymbolTokens;

import java.io.IOException;
import software.amazon.ion.EmptySymbolException;
import software.amazon.ion.IonType;
import software.amazon.ion.SymbolTable;
import software.amazon.ion.SymbolToken;
Expand Down Expand Up @@ -366,9 +365,9 @@ public final void setFieldName(String name)
if (!this.isInStruct()) {
throw new IllegalStateException();
}
if (name.length() == 0) {
throw new EmptySymbolException();
}

name.getClass(); // fast null check

_field_name_type = IonType.STRING;
_field_name = name;
_field_name_sid = UNKNOWN_SYMBOL_ID;
Expand All @@ -383,9 +382,6 @@ public final void setFieldNameSymbol(SymbolToken name)
String text = name.getText();
if (text != null)
{
if (text.length() == 0) {
throw new EmptySymbolException();
}
_field_name_type = IonType.STRING;
_field_name = text;
_field_name_sid = UNKNOWN_SYMBOL_ID;
Expand Down
33 changes: 8 additions & 25 deletions src/software/amazon/ion/impl/LocalSymbolTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import software.amazon.ion.EmptySymbolException;
import software.amazon.ion.IonCatalog;
import software.amazon.ion.IonException;
import software.amazon.ion.IonList;
Expand Down Expand Up @@ -333,17 +332,14 @@ private LocalSymbolTable(LocalSymbolTable other, int maxId)
IonType type;
while ((type = reader.next()) != null)
{
String text = null;
final String text;
if (type == IonType.STRING)
{
// As per the Spec, if any element of
// the list is the empty string or any
// other type, treat it as null
text = reader.stringValue();
if (text != null && text.length() == 0)
{
text = null;
}
}
else
{
text = null;
}

symbolsList.add(text);
Expand Down Expand Up @@ -483,11 +479,6 @@ else if (id < myFirstLocalSid)

public int findSymbol(String name)
{
if (name.length() < 1) // throws NPE if null
{
throw new EmptySymbolException();
}

// Look in system then imports
int sid = myImportsList.findSymbol(name);

Expand All @@ -502,8 +493,6 @@ public int findSymbol(String name)

private int findLocalSymbol(String name)
{
assert(name.length() > 0);

Integer isid;
synchronized (this)
{
Expand Down Expand Up @@ -533,10 +522,7 @@ public synchronized SymbolToken intern(String text)

public SymbolToken find(String text)
{
if (text.length() < 1)
{
throw new EmptySymbolException();
}
text.getClass(); // fast null check

// Look in system then imports
SymbolToken symTok = myImportsList.find(text);
Expand Down Expand Up @@ -566,10 +552,9 @@ public SymbolToken find(String text)

private static final void validateSymbol(String name)
{
if (name == null || name.length() < 1)
if (name == null)
{
String message = "symbols must contain 1 or more characters";
throw new IllegalArgumentException(message);
throw new IllegalArgumentException("symbols must not be null");
}
for (int i = 0; i < name.length(); ++i)
{
Expand Down Expand Up @@ -607,8 +592,6 @@ private static final void validateSymbol(String name)
*/
private int putSymbol(String symbolName)
{
assert symbolName.length() != 0;

if (isReadOnly)
{
throw new ReadOnlyValueException(SymbolTable.class);
Expand Down
77 changes: 37 additions & 40 deletions src/software/amazon/ion/impl/PrivateIonTextAppender.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import software.amazon.ion.Decimal;
import software.amazon.ion.EmptySymbolException;
import software.amazon.ion.impl.Base64Encoder.TextStream;
import software.amazon.ion.system.IonTextWriterBuilder;
import software.amazon.ion.util.PrivateFastAppendable;
Expand Down Expand Up @@ -410,6 +409,12 @@ public static boolean isIdentifierKeyword(CharSequence text)
{
int pos = 0;
int valuelen = text.length();

if(valuelen == 0)
{
return false;
}

boolean keyword = false;

// there has to be at least 1 character or we wouldn't be here
Expand Down Expand Up @@ -473,51 +478,51 @@ else if (valuelen == 3 // 'n'
*
* @throws NullPointerException
* if <code>symbol</code> is <code>null</code>.
* @throws EmptySymbolException if <code>symbol</code> is empty.
*/
public static boolean symbolNeedsQuoting(CharSequence symbol,
boolean quoteOperators)
{
int length = symbol.length();
if (length == 0) {
throw new EmptySymbolException();
}

// If the symbol's text matches an Ion keyword, we must quote it.
// Eg, the symbol 'false' must be rendered quoted.
if (! isIdentifierKeyword(symbol))
// If the symbol's text matches an Ion keyword or it's an empty symbol, we must quote it.
// Eg, the symbol 'false' and '' must be rendered quoted.
if(length == 0 || isIdentifierKeyword(symbol))
{
char c = symbol.charAt(0);
// Surrogates are neither identifierStart nor operatorPart, so the
// first one we hit will fall through and return true.
// TODO test that
return true;
}

if (!quoteOperators && isOperatorPart(c))
{
for (int ii = 0; ii < length; ii++) {
c = symbol.charAt(ii);
// We don't need to look for escapes since all
// operator characters are ASCII.
if (!isOperatorPart(c)) {
return true;
}
char c = symbol.charAt(0);

// Surrogates are neither identifierStart nor operatorPart, so the
// first one we hit will fall through and return true.
// TODO test that

if (!quoteOperators && isOperatorPart(c))
{
for (int ii = 0; ii < length; ii++) {
c = symbol.charAt(ii);
// We don't need to look for escapes since all
// operator characters are ASCII.
if (!isOperatorPart(c)) {
return true;
}
return false;
}
else if (isIdentifierStart(c))
{
for (int ii = 0; ii < length; ii++) {
c = symbol.charAt(ii);
if ((c == '\'' || c < 32 || c > 126)
|| !isIdentifierPart(c))
{
return true;
}
return false;
}
else if (isIdentifierStart(c))
{
for (int ii = 0; ii < length; ii++) {
c = symbol.charAt(ii);
if ((c == '\'' || c < 32 || c > 126)
|| !isIdentifierPart(c))
{
return true;
}
return false;
}
return false;
}

// quote by default
return true;
}

Expand All @@ -534,10 +539,6 @@ public final void printSymbol(CharSequence text)
{
appendAscii("null.symbol");
}
else if (text.length() == 0)
{
throw new EmptySymbolException();
}
else if (symbolNeedsQuoting(text, true)) {
appendAscii('\'');
printCodePoints(text, SYMBOL_ESCAPE_CODES);
Expand All @@ -561,10 +562,6 @@ public final void printQuotedSymbol(CharSequence text)
{
appendAscii("null.symbol");
}
else if (text.length() == 0)
{
throw new EmptySymbolException();
}
else
{
appendAscii('\'');
Expand Down
Loading