-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds serializability checks for UDFs
-- adds check to catch any issues with serializability at UDF initialization time (i.e when the udf object is created) -- moves internal UDFProcessing/FatalErrors to udf package -- wraps error on loading udfs to propagate to a UDFFatalError -- adds associated tests/test classes DAFFODIL-2235
- Loading branch information
1 parent
5ec9ba9
commit a098134
Showing
11 changed files
with
351 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
daffodil-runtime1/src/main/scala/org/apache/daffodil/udf/UserDefinedFunctionErrors.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.daffodil.udf | ||
|
||
import org.apache.daffodil.exceptions.Abort | ||
import org.apache.daffodil.processors.ProcessingError | ||
import org.apache.daffodil.util.Maybe | ||
import org.apache.daffodil.exceptions.SchemaFileLocation | ||
import org.apache.daffodil.api.DataLocation | ||
import org.apache.daffodil.util.Misc | ||
|
||
/** | ||
* User Defined Function Exception class to wrap processing errors from the UDF | ||
* into Daffodil Processing Errors | ||
*/ | ||
case class UserDefinedFunctionProcessingErrorException( | ||
errorInfo: String, | ||
schemaContext: Maybe[SchemaFileLocation], | ||
dataContext: Maybe[DataLocation], | ||
errorCause: Maybe[Throwable], | ||
errorStr: Maybe[String]) | ||
extends ProcessingError(errorInfo, schemaContext, dataContext, errorCause, errorStr) | ||
|
||
/** | ||
* User Defined Function Exception class to wrap fatal errors from the UDF | ||
* into Daffodil Aborts | ||
*/ | ||
case class UserDefinedFunctionFatalErrorException(description: String = "", cause: Throwable, udfOfInterest: String = "", providerOfInterest: String = "") | ||
extends Abort(description + ": " + cause.getMessage) { | ||
|
||
/* | ||
* This will replace the stacktrace of the fatal error with just the UDF relevant | ||
* portions; removing the Daffodil (incl our evaluate invocation) and the Method | ||
* reflection portions. | ||
* | ||
*/ | ||
val classesOfInterest = List(udfOfInterest, providerOfInterest).filterNot(Misc.isNullOrBlank) | ||
if (classesOfInterest.nonEmpty) { | ||
val curStackTrace = cause.getStackTrace | ||
val indexLastUdfEntry = curStackTrace.lastIndexWhere(ste => classesOfInterest.exists(_ == ste.getClassName)) | ||
val finalStackTrace = | ||
if (indexLastUdfEntry >= 0) curStackTrace.slice(0, indexLastUdfEntry + 1) | ||
else curStackTrace | ||
this.setStackTrace(finalStackTrace) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.