Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid using 'return' #840

Merged
merged 1 commit into from
May 19, 2024
Merged
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 @@ -39,32 +39,32 @@ object SchemaHelper {
// this is totally not FP but what the heck it's late and it's perfectly valid
arrayTypeNamePattern.findFirstMatchIn(fullName) match {
case Some(_) =>
return types.asScala.find(_.getType == Schema.Type.ARRAY).getOrElse {
types.asScala.find(_.getType == Schema.Type.ARRAY).getOrElse {
throw new Avro4sConfigurationException(s"Could not find array type to match $fullName")
}
case None =>
}
// Finds the matching schema and keeps track a null type if any.
// If the schema is size 2, and one of them is null, then the other type is returned, regardless of its name.
// See https://github.com/sksamuel/avro4s/issues/268
var result: Schema = null
var nullIndex: Int = -1
var i = 0
while
i < size && result == null
do
val s = types.get(i)
if (s.getFullName == fullName) result = s
else if (s.getType == Schema.Type.NULL) nullIndex = i
i = i + 1

if (result != null) { // Return the name based match
result
} else if (nullIndex != -1 && size == 2) { // Return the non null type.
types.get(i - nullIndex)
} else {
throw new Avro4sConfigurationException(s"Cannot find subschema for type [$fullName] in ${union.getTypes}")
}

// Finds the matching schema and keeps track a null type if any.
// If the schema is size 2, and one of them is null, then the other type is returned, regardless of its name.
// See https://github.com/sksamuel/avro4s/issues/268
var result: Schema = null
var nullIndex: Int = -1
var i = 0
while
i < size && result == null
do
val s = types.get(i)
if (s.getFullName == fullName) result = s
else if (s.getType == Schema.Type.NULL) nullIndex = i
i = i + 1

if (result != null) { // Return the name based match
result
} else if (nullIndex != -1 && size == 2) { // Return the non null type.
types.get(i - nullIndex)
} else {
throw new Avro4sConfigurationException(s"Cannot find subschema for type [$fullName] in ${union.getTypes}")
}
}

Expand Down
Loading