I have NullPointerException [no message] in my luminus application. The code is quite long to post it here and I can't find the source of the error. Neither there's any mention of "NullPointerException [no message]" in the logs, and in the browser the error just doesn't make sense and the exact place and variables where the error is caused aren't shown precisely.
How can I trace what causes the error?
the approach that i take for such errors is
if it is a new error (started happening recently), then most probably it is being caused by the code that was added recently. so use that code as the starting point
see if there are any API calls which might be returning a nil value. try to replace every API w/ a real hardcoded value, one-by-one, and see if you're still seeing the error
once you figure out which API call is returning nil, then dig deeper to see if you're passing any wrong arguments to the API, or causing some case due to which it is returning the nil
HTH :)
Clojure's error messages can be hell but they aren't useless. Take a look at this link:
https://8thlight.com/blog/connor-mendenhall/2014/09/12/clojure-stacktraces.html
It helped me out and hope it can do the same for you
Null pointer exception is caused because of accessing / using a variable which holds the value. As a programmer we have to do null chuck to the variable which are returning a value from other functions.
If you want to trace it just keep debug point from which action you are getting this error n chuck which variable your accessing as null value.
Related
In the following project
https://github.com/Crash1hd/MultipleTestTesting
I am getting the following error
java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[DefaultDispatcher-worker-1 #coroutine#3,5,SDK 28] []
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.getConnection(ShadowSQLiteConnection.java:367)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:416)
at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:89)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:562)
at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:323)
at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:298)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:549)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:460)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.beginTransaction(FrameworkSQLiteDatabase.java:69)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:277)
at com.mycomp.roomwordsample.data.db.WordDao_Impl.deleteAll(WordDao_Impl.java:81)
at com.mycomp.roomwordsample.data.db.WordRepository$deleteAllLogsOlderThan$2.invokeSuspend(WordRepository.kt:28)
at |b|b|b(Coroutine boundary.|b(|b)
at com.mycomp.roomwordsample.ui.WordViewModel$deleteAllLogsOlderThanA$1.invokeSuspend(WordViewModel.kt:36)
Caused by: java.lang.IllegalStateException: Illegal connection pointer 1. Current pointers for thread Thread[DefaultDispatcher-worker-1 #coroutine#3,5,SDK 28] []
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.getConnection(ShadowSQLiteConnection.java:367)
at org.robolectric.shadows.ShadowSQLiteConnection$Connections.prepareStatement(ShadowSQLiteConnection.java:416)
at org.robolectric.shadows.ShadowSQLiteConnection.nativePrepareStatement(ShadowSQLiteConnection.java:89)
at android.database.sqlite.SQLiteConnection.nativePrepareStatement(SQLiteConnection.java)
at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:903)
at android.database.sqlite.SQLiteConnection.execute(SQLiteConnection.java:562)
at android.database.sqlite.SQLiteSession.beginTransactionUnchecked(SQLiteSession.java:323)
at android.database.sqlite.SQLiteSession.beginTransaction(SQLiteSession.java:298)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:549)
at android.database.sqlite.SQLiteDatabase.beginTransaction(SQLiteDatabase.java:460)
at androidx.sqlite.db.framework.FrameworkSQLiteDatabase.beginTransaction(FrameworkSQLiteDatabase.java:69)
at androidx.room.RoomDatabase.beginTransaction(RoomDatabase.java:277)
at com.mycomp.roomwordsample.data.db.WordDao_Impl.deleteAll(WordDao_Impl.java:81)
at com.mycomp.roomwordsample.data.db.WordRepository$deleteAllLogsOlderThan$2.invokeSuspend(WordRepository.kt:28)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)
at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:594)
at kotlinx.coroutines.scheduling.CoroutineScheduler.access$runSafely(CoroutineScheduler.kt:60)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:742)
When I run this set of tests
https://github.com/Crash1hd/MultipleTestTesting/blob/master/app/src/test/java/com/mycomp/roomwordsample/WordDaoTestA.kt
It seems to have to do with the function that I am calling in initializationLogging in WordApplication
https://github.com/Crash1hd/MultipleTestTesting/blob/master/app/src/main/java/com/mycomp/roomwordsample/WordApplication.kt
Commenting out LogA.purgeOldLogsGreaterThan(7) this line all the tests pass.
I am at a loss as to why it is failing? each test is exactly the same and they all work (just not all at once).
I am wondering if it has to do with how I am calling the WordViewModel in application...
Ok So I came across this blog post
https://artemzin.com/blog/how-to-mock-dependencies-in-unit-integration-and-functional-tests-dagger-robolectric-instrumentation/
and in the comments, there is this comment by Krzysiek Bielicki
You can just create Application class prefixed with 'Test'. Robolectric will automatically use it as Application for all tests.
So I tried that created class TestWordApplication added everything that was in WordApplication (but excluded the call to initializationLogging() and now all the test pass as its no longer trying to access and purge the actual database.
I found this also on the Robolectric website confirming
http://robolectric.org/custom-test-runner/
Thanks. and a very special thank you to Krzysiek Bielicki (whomever you are) as you just made my night :)
So I'm getting this error every so often when running the exact same test.
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.41.578706 (5f725d1b4f0a4acbf5259df887244095596231db),platform=Mac OS X 10.12.6 x86_64)
The only problem is that it seems to happen inconsistently to different areas of the code. It's when trying to access DOM elements, like a search field, of my ReactJS page. I'm running this through ROBOT Automation Framework, using a mix of the SeleniumLibrary and a custom library.
I've read that it's simply as it sounds, the xPath as become outdated on the DOM, but that doesn't help me figure out why it's an inconsistent error happening almost anywhere at any point.
EDIT: It seems to be happening in this:
def filter_modality(self, filter):
filter_value = '//span[#title="{}"]//parent::li'.format(filter)
self.selib.click_element(filter_locator)
self.selib.wait_until_page_contains_element('//*[#class="multi-selector-options open"]')
self.selib.wait_until_element_is_visible(filter_value)
self.selib.click_element(filter_value )
self.selib.wait_until_page_contains_element('//div...[#class="option selector-item active"]',
error=("Could not select filter: {}".format(filter_value )))
#I get the stale element message from or after executing this click_element
self.selib.click_element(filter_locator)
self.selib.wait_until_page_does_not_contain_element('//*[#class="multi-selector-options open"]',
error="Filter dropdown did not disappear after selection")
The exception comes when SE has found an element, but shortly afterwards something (a JS function) has changed it - removed from/rearranged it in the DOM, or changed its attributes significantly, so it's no longer tracked as the same element.
This comes for the fact that SE builds an internal cache of the DOM, which may become desynchronized from the actual one; thus the name "stale" - the el. is cached in some state, but its actual form is now different.
The issue is that common, that there is a specific SO tag for it - https://stackoverflow.com/questions/tagged/staleelementreferenceexception (I myself was surprised from this).
The common solutions are:
sleep for some seconds before an event you know will cause the issue
re-get an element before its usage (if you store a reference to it in a WebElement object, not really the case with robotframework)
have a rertry mechanism on working with an element that you know may cause the execution
swallow the exception and move along (I've done it in a few places, where the element was just a confirmation an operation was executed - it has been shown/found by SE once, afterwards I don't care is it changed in the DOM)
While in any particular case there are hints and clues on how to debug an error you get, I haven't really found a general Ember strategy.
For example, a typeError while loading a route:
Assertion failed: Error while loading route: TypeError: 'undefined' is not an object (evaluating 'window.router.lander') (ignore the fact that I'm trying to access window.router.lander. It's irrelevant)
Why does Ember not tell you which route it's loading when this error happens? Or whether it happens in afterModel(), or activate()? And what's the general strategy for finding that sort of context info?
So far all I've got is adding a bunch of console.logs scattered around. For example with the error above:
1) Find all occurrences of window.router.lander in my code
2) before the first occurrence, add a console.log('is it the first occurrence?'), and after the first occurrence put a console.log('its not the first occurrence')
3) Do the same for every occurrence
4) refresh. One of the 'is it the nth occurrence?' won't have a closer, and now you know where the error happened.
For better debugging, you can enable transitions logging by create app with LOG_TRANSITIONS and/or LOG_TRANSITIONS_INTERNAL properties:
window.App = Ember.Application.create({
// Basic logging, e.g. "Transitioned into 'post'"
LOG_TRANSITIONS: true,
// Extremely detailed logging, highlighting every internal
// step made while transitioning into a route, including
// `beforeModel`, `model`, and `afterModel` hooks, and
// information about redirects and aborted transitions
LOG_TRANSITIONS_INTERNAL: true
});
Referenece: http://emberjs.com/guides/understanding-ember/debugging/
Also, you can use canary build which provide detailed error stack:
http://emberjs.com/builds/#/canary
Ember isn't particularly helpful when it comes to errors in the model hook, or the promises it returns. I'm sure I've read in one of the issues (or http://discuss.emberjs.com/ I'm not sure) that this is an open issue in which they're working.
What I do is use the Chrome Developer Tools to debug the issue (instead of just console loggin it). From my experience it's usually:
you're not returning anything in the model hook
an error inside one of the then functions on the promise the model hook returns
I hope it helps you!
So I have a remote ColdFusion Function like:
remote string function name (required numeric varname){
This is accessed via AJAX call. Google has taken it upon itself to pass in junk/blank values to the URL to this remote function. How can I gracefully handle those for Bots/Users to manage to get in a junk value. I've tried putting try/catch around/inside the function and doesn't work. I've also tried setting a default value but I still get an error. I'd like to be able to return an error message.
Thoughts?
Right now:
domain.com/path/to/page.cfc?method=function&varname=
Is throwing an error
domain.com/path/to/page.cfc?method=function&varname=5
Is working as expected.
Update:
I am leaving this here for posterity, as it explains the cause of the error and chain of events with validation. However, Adam's response is the correct solution IMO.
remote string function name (required numeric varname){
I've tried putting try/catch around/inside the function and doesn't work.
Because the argument value is validated before CF executes anything inside the function. So it never even gets to the try/catch.
If you want to allow non-numeric values, you must set the argument type to string and perform validation inside the function. ie
// use whatever check is appropriate here
if ( IsNumeric(arguments.varname) ) {
// good value. do something
}
else {
// bad value. do something else
}
I've also tried setting a default value but I still get an error
domain.com/path/to/page.cfc?method=function&varname=
Update
The reason it does not work is because the varname parameter does exists. Its value is an empty string. As long as some value is passed (even an empty string) the default is ignored.
I disagree that the accepted solution is the best approach here.
Firstly, if your method is expecting a numeric and it's being passed a string, then an error is precisely the correct reaction here. You shouldn't feel the need to mitigate for requests that pass invalid values. Consider it like someone making a request to http://some.domain/path/to/file/wrongOne.html (they should have requested http://some.domain/path/to/file/rightOne.html)... it's completely OK for things to return a 404 "error" there, isn't it? An error response is exactly right in that situation.
Similarly, you have dictated that for your remote call URL, that argument is supposed to be numeric. So if it's not numeric... that is an error condition. So your server returning a 500-type error is actually the correct thing to do.
This is an example of the "garbage in, garbage out" rule.
If you are looking for an elegant solution, I'd say you already have the most elegant solution. Don't mess around writing special code to deal with incorrectly made requests. That is not an elegant approach.
You are better off letting the thing error, because then the mechanism requesting the URL will stop doing it. Messing around so that you are returning a 200 OK for a request that wasn't "OK" is the wrong thing to do.
Errors - when they are the correct result - are fine. There's nothing wrong with them.
i just switched to ember-latest v1.0.pre-160-g7d62790, from v1.0.pre-42 and now my router is throwing the error : TypeError: Object hash has no method 'getURL' when it is starting up.
the app is auto initializing. i've dug into the source and the offending line is 11264: router.route(location.getURL());
in this case location is 'hash' which is the default value of Router.location.. i think it's supposed to get set as a HashLocation internally when the router initializes.. hence the getURL() call.
but it's remaining as a string. i suspect this has to do with some kind of initializing being out of whack, but i can figure out why. anyone else encountered this, or know why it's happening?
solved it myself. the issue was that i overrode Router.initialize() but did not call super() within it, so the Router didn't complete its initialization.