stevedlawrence commented on a change in pull request #226: Sick of NPE.
lexicalParent is now optLexicalParent and is Option type
URL: https://github.com/apache/incubator-daffodil/pull/226#discussion_r291171653
##########
File path:
daffodil-core/src/main/scala/org/apache/daffodil/dsom/SchemaComponentFactory.scala
##########
@@ -79,14 +81,14 @@ trait SchemaFileLocatableImpl
trait CommonContextMixin
extends NestingMixin { self: OOLAGHost with ThrowsSDE =>
- def lexicalParent: SchemaComponent
+ def optLexicalParent: Option[SchemaComponent]
- lazy val schemaFile: Option[DFDLSchemaFile] = lexicalParent.schemaFile
- lazy val schemaSet: SchemaSet = lexicalParent.schemaSet
- def schemaDocument: SchemaDocument = lexicalParent.schemaDocument
- lazy val xmlSchemaDocument: XMLSchemaDocument =
lexicalParent.xmlSchemaDocument
- lazy val schema: Schema = lexicalParent.schema
- def uriString: String = lexicalParent.uriString
+ lazy val schemaFile: Option[DFDLSchemaFile] = optLexicalParent.flatMap {
_.schemaFile }
Review comment:
I was just saying this more for consistency. schemaFile is already an
option, so ``optLexicalParent.get.schemaFile`` should return the that value
option value. The difference between that and what you have is that if
optLexicalParent isn't defined, schemaFile will be set to None rather than
throwing a NoSuchElementException. But the code below already assumes
optLexicalParent is defined, so the result should be exactly the same.
I guess the thing that confused me was was this line change was different
than the ones below and I had to think about if there was a reason for that,
and it wasn't clear to me if there was a reason or not. But returning an Option
is reasonable. This is fine with me.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services