How can I call JTable.getColumn(x) in Kotlin? The obvious code:
table.getColumn(0)
Results in this Exception:
java.lang.IllegalArgumentException: Identifier not found
Related
I have following code in Kotlin:
sealed class ParentClass
data class ChildA(val prop: String): ParentClass()
object ChildB: ParentClass()
but when I try to serialize it into JSON with Moshi I get following Error:
Caused by: java.lang.IllegalArgumentException: Cannot serialize object declaration ChildB
Failed to serialize obj: ChildB of type: class ChildB to a map
I don't want to include full stack trace due to confidentiality, but essentially it fails on this line. I wonder if there is a way to serialize Kotlin object types into JSON and back?
https://github.com/ZacSweers/MoshiX/tree/main/moshi-sealed should support that use case, I believe.
How can I use Junit4 to test the thrown exception while using the exception mapper ?
To test a thrown exception, expected from the execution. Please use :
#Test(expected=<ExpectedException>.class)
public void testThrownException() {
// Your test code that throws the expected exception
}
The test would pass if your code throws the expected exception and fail for assertion failures and any other exception thrown by the code.
While unit testing in actionscript-3 with mockolate I have run into quite a few problems/errors:
Error: No Expectation defined for Invocation:[FloxyInvocation invocationType=GETTER name="propertyName" arguments=[]]
Error: 1 unmet Expectation
Mockolate errors and debugging are poorly documented and searches bring up no results, so solving these problems get very tricky.
No expectation defined error is thrown when the function you are testing expects the specified invocation type and name:
Error: No Expectation defined for Invocation:[FloxyInvocation invocationType=GETTER name="propertyName" arguments=[]]
Can be solved with:
mock(object).getter("propertyName").returns(someValue);
Unmet expectation error can be thrown when you created a mock statement (a getter or setter) but there is no getter or setter defined for the variable you are getting or setting.
Error: 1 unmet Expectation
Can be solved with:
public function get variable():String {
return _variable;
}
public function set variable(value:String):void {
_variable = value;
}
Using Groovy / Grails and log4j is there any way to ensure every exception thrown in the code is logged at error level.
Rather than having to find every catch block and explictly log it?
If not groovy / grails - a java suggestion will suffice.
Thanks
I don't believe there's any way to do this for handled exceptions, but you can do it for unhandled exceptions by adding the following to UrlMappings.groovy
"500"(controller: 'error')
Then create an ErrorController.groovy under grails-app/controllers
class ErrorController {
def index() {
Throwable exception = request?.exception?.cause
log.error 'something bad happened', exception
}
}
I've written an ExceptionMapper in order to catch all http exception (400,404,500,...) in my application.
#Provider
public class MyExceptionHandler implements ExceptionMapper<Exception> {
#Override
public Response toResponse(Exception ex) {
//Some Code to build Response
}
unfortunately when I send a post request with Content-Type:application/json with empty or wrong format body, this error occurs and I can not catch it in MyExceptionHandler.
Status Code: 400 Bad Request
No content to map due to end-of-input
at [Source: org.apache.catalina.connector.CoyoteInputStream#5774bb5e; line: 1, column: 1]
what did I do wrong?
Thanks a lot.
Environment: JAX-RS, GlassFish 3
Edit:
I think this error is related to AppServer and must be handled there.
When there is a bad request such as wrong format body, the WebApplicationException is thrown. Here is how exception mappers are selected
When a WebApplicationException, or one of its subclasses, with an
empty entity body is thrown, the runtime will check to see if there
is an exception mapper that handles WebApplicationException
exceptions. If there is the exception mapper is used to create the
response sent to the consumer.
When any exception other than a WebApplicationException exception, or
one of its subclasses, is thrown, the runtime will check for an
appropriate exception mapper. An exception mapper is selected if it
handles the specific exception thrown. If there is not an exception
mapper for the specific exception that was thrown, the exception
mapper for the nearest superclass of the exception is selected.
Here is what I would recommend
register an ExceptionMapper<WebApplicationException>
register an ExceptionMapper<Throwable> to catch all other exceptions with a generic response signaling a 500 sever error.