junyuc25 commented on PR #47354: URL: https://github.com/apache/spark/pull/47354#issuecomment-2283928413
Hi @MaxGekk , looks like the current implementation is causing an error when generating docs ([job link](https://github.com/junyuc25/spark/actions/runs/10349944541/job/28645454259)), because SparkException is declared in the comment but it is not thrown from the codes. ``` [error] /__w/spark/spark/sql/api/target/java/org/apache/spark/sql/Row.java:135:1: error: exception not thrown: org.apache.spark.SparkException [error] * @throws org.apache.spark.SparkException when value is null. [error] ^ [warn] javadoc exited with exit code 1 ``` I found two options to fix this: 1. Add `@throws[SparkException]` annotation to the method. This is equivalent to adding `throws XXException` to a Java method signature (i.e. `public boolean getBoolean (int i) throws org.apache.spark.SparkException`), and hence Java consumers of this method would need to catch this exception explicitly. ``` /** * Returns the value at position i as a primitive boolean. * * @throws ClassCastException when data type does not match. * @throws org.apache.spark.SparkException when value is null. */ @throws[SparkException] def getBoolean(i: Int): Boolean = getAnyValAs[Boolean](i) ``` 2. Do not add `@throws org.apache.spark.SparkException` to the comment, and also remove `@throws NullPointerException` (because NPE would not be thrown from the codes). ``` /** * Returns the value at position i as a primitive boolean. * * @throws ClassCastException when data type does not match. */ def getBoolean(i: Int): Boolean = getAnyValAs[Boolean](i) ``` I kind of lean towards option #1 as it could provide users with better context about the exception type being thrown, although they would have to handle this exception explicitly in their codes. Let me know your thought on this or if you have other ideas. Thanks :)! -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
