Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Object avroFriendlyDefault;
try {
avroFriendlyDefault = avroFriendlyDefaultValue(_defaultVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Object avroFriendlyDefault;
try {
avroFriendlyDefault = avroFriendlyDefaultValue(_defaultVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Schema.Field result = new Schema.Field(_name, _schema, _doc, _defaultVal, _order);
if (_props != null && !_props.isEmpty()) {
Map<String, String> clonedProps = getProps(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Schema.Field result = new Schema.Field(_name, _schema, _doc, _defaultVal, _order);
if (_props != null && !_props.isEmpty()) {
Map<String, String> clonedProps = getProps(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Schema.Field result = new Schema.Field(_name, _schema, _doc, _defaultVal, _order);
if (_props != null) {
for (Map.Entry<String, String> entry : _props.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Schema.Field result = new Schema.Field(_name, _schema, _doc, _defaultVal, _order);
if (_props != null) {
Avro17Utils.setProps(result, _props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
@SuppressWarnings("deprecation") //deprecated but faster
Schema.Field result = new Schema.Field(_name, _schema, _doc, _defaultVal, _order);
if (_props != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ public FieldBuilder copyFromField() {

@Override
public Schema.Field build() {
if (_schema == null) {
throw new IllegalStateException("schema not set");
}
Object avroFriendlyDefault;
try {
avroFriendlyDefault = avroFriendlyDefaultValue(_defaultVal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ public void testNewFieldSortOrder() throws Exception {
}
}

@Test
public void testBuildFailsOnNullSchema() throws Exception {
try {
AvroCompatibilityHelper.newField(null).setName("noSchema").build();
Assert.fail("expected an exception");
} catch (IllegalStateException expected) {
// pass - schema is required for a field to be built
}
}

private void setDefaultValues(Schema.Field field) {
Assert.assertTrue(AvroCompatibilityHelper.fieldHasDefault(field));
Schema fieldSchema = field.schema();
Expand Down