To suppress or not to suppress (deprecation warning)? - android-studio

I have the following code in Android Studio Dolphin:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH) {
powerManager.isScreenOn();
} else {
powerManager.isInteractive();
}
When I run Code > Inspect code... I see warning messages:
warning: [deprecation] isScreenOn() in PowerManager has been deprecated
But if I add
#SuppressWarnings("deprecation")
I then see the warning
Redundant suppression
which obviously is.
So, no matter what I do, I see warning messages...

Related

ESLint unexpected token in calculated object key

Using the latest rules from eslint-config-react-app we get the following linting error:
{
[componentWidth > VIEW_DESKTOP && componentWidth <= VIEW_LARGE]: MAX_TICKS_LARGE
}
error Parsing error: Unexpected token
The issue seems to be located at <= in the calculated key.
Does anyone know what's causing this to throw an error? The code should be legit.
Update: interestingly, the linting error doesn't show up in my IDE, only in the console.
Update 2: Seems to be an issue with eslint latest version rather than anything related to eslint-config-react-app. Using the eslint version specified by eslint-config-react-app works fine, just not with the latest version of eslint.
Update 3
To provide a better context for the problem, here's the function within which this code exists:
const getTicksToDisplay = (componentWidth) => {
const truthMap = {
[true]: MIN_TICKS_ON_SCREEN,
[componentWidth > VIEW_LARGE]: MAX_TICKS_XLARGE,
[componentWidth > VIEW_DESKTOP && componentWidth <= VIEW_LARGE]: MAX_TICKS_LARGE,
[componentWidth > VIEW_TABLET && componentWidth <= VIEW_DESKTOP]: MAX_TICKS_DESKTOP,
[componentWidth > VIEW_MOBILE && componentWidth <= VIEW_TABLET]: MAX_TICKS_TABLET,
[componentWidth <= VIEW_MOBILE]: MAX_TICKS_MOBILE
};
return truthMap[true];
};
Update 4
The version of eslint at the time of asking this question was 3.11.1. The code works in eslint 3.8.1 and since asking this question, eslint 3.12.0 has been released (which I haven't been able to test against yet)
Update 5
Upon further testing it looks like this might be an issue with babel-eslint 7.1.1. I've raised an issue: https://github.com/babel/babel-eslint/issues/428

Grails 2.4.3 considers FATAL log level as ERROR

I'm learning about log4j configuration in Grails. Below is my Config.groovy. The logger grails.app.controllers.logging.FatalController is configured to log fatal level only.
log4j.main = {
// Example of changing the log pattern for the default console appender:
//
//appenders {
// console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
//}
fatal 'grails.app.controllers.logging.FatalController'
error 'org.codehaus.groovy.grails.web.servlet', // controllers
'org.codehaus.groovy.grails.web.pages', // GSP
'org.codehaus.groovy.grails.web.sitemesh', // layouts
'org.codehaus.groovy.grails.web.mapping.filter', // URL mapping
'org.codehaus.groovy.grails.web.mapping', // URL mapping
'org.codehaus.groovy.grails.commons', // core / classloading
'org.codehaus.groovy.grails.plugins', // plugins
'org.codehaus.groovy.grails.orm.hibernate', // hibernate integration
'org.springframework',
'org.hibernate',
'net.sf.ehcache.hibernate'
warn 'grails.app.services.logging.WarnService',
'grails.app.controllers.logging.WarnController'
This is my FatalController.groovy:
package logging
class FatalController {
def index(){
log.debug("This is not shown")
log.warn("neither this")
log.error("or that")
log.fatal("but this does")
render "logged"
}
}
Now, when I execute this I expected it to log "but this does". However it doesn't. When I changed Config.groovy line:
fatal 'grails.app.controllers.logging.FatalController'
to this:
all 'grails.app.controllers.logging.FatalController'
The output I get is this:
2014-10-15 12:33:04,070 [http-bio-8080-exec-2] DEBUG logging.FatalController - This is not shown
2014-10-15 12:33:04,071 [http-bio-8080-exec-2] WARN logging.FatalController - neither this
| Error 2014-10-15 12:33:04,072 [http-bio-8080-exec-2] ERROR logging.FatalController - or that
| Error 2014-10-15 12:33:04,072 [http-bio-8080-exec-2] ERROR logging.FatalController - but this does
Notice that the message "but this does" is defined in FatalController.groovy to be logged as fatal
log.fatal("but this does")
And what the log message say is that it is a ERROR level message log:
| Error 2014-10-15 12:33:04,072 [http-bio-8080-exec-2] ERROR logging.FatalController - but this does
So there are two problems: 1) FATAL log messages are not shown when the logger level is defined as FATAL and 2) when I code log.fatal("something"), the log shows it as an ERROR level message.
What am I doing wrong here?
I think it's a Grails bug (I'm using Grails 2.4.5).
I found a workaround: try to use log4j in "old way".
import org.apache.log4j.Logger
class FatalController {
Logger log = Logger.getLogger(getClass())
def index() {
// ...
}
}

Error "Unable to get property 'normalize' of undefined or null reference" in require.js with text.js

I'm making my first attempt at using the text.js plugin (v2.0.12) for require.js (v2.1.15). I've had require working well up to this point, however, when I attempt to resolve a text dependency, I get two errors. The first error is Unable to get property 'normalize' of undefined or null reference [require.js, Line: 955] then, after the allotted time, I'll get a timeout error for the html file I'm attempting to load. The focus of this cry for help is the former error.
One curious observation I've noticed is that if I resolve the text module without declaring a file, there is no error. However, when I add the file path e.g. text!path/file, the error is triggered.
Additionally, I noticed that the load timeout error references the text module with _unnormalized2 appended. Not sure if that's to be expected but I thought is odd. Any help would be greatly appreciated!
Here's the block of code which errors:
//If current map is not normalized, wait for that
//normalized name to load instead of continuing.
if (this.map.unnormalized) {
//Normalize the ID if the plugin allows it.
if (plugin.normalize) { // error occurs here (line 955)
name = plugin.normalize(name, function (name) {
return normalize(name, parentName, true);
}) || '';
}
// ...
}
Ok, it turns out to have been a self-sabotage! I was creating a shortcut definition for the text module for which I left out the factory method. So, instead of
define('text', ['Scripts/text'], function(text) { return text; });
I had:
define('text', ['Scripts/text']);
Nothing to do with text.js whatsoever.

Error.getStackTrace() returns a string unparseable in flashdevelop?

Accessing a string created by an Error's getStackTrace function is resulting in very unusual behaviour in the FlashDevelop IDE.
package
{
import flash.display.Sprite;
public class Main extends Sprite
{
public function Main():void
{
print("Start");
var err:Error = new Error();
var stack:String = err.getStackTrace();
print(stack);
// also occurs when this is replaced with stack.length or stack[0]
print("End");
}
private function print(input:*):void
{
trace(input);
trace("---");
}
}
}
When run in flash CS4 that outputs
Start
---
Error
at Main()
---
End
---
But when run in FlashDevelop (replacing trace() with FlashConnect.trace()) it outputs
Start
---
Is that a bug, or is it FlashDevelop handling errors in a different way intentionally?
If it is the latter is there a workaround to access the stacktrace of an error?
I managed to fix this by switching to using a dubugging version of the flash player, i hope this helps anyone else with this problem.
instructions for specifying a debug player
Make sure you are compiling in Debug configuration and you may have to enable (set True) "Verbose Stack Trace" in your Project Properties > Compiler Options

How to handle V8 engine crash when process runs out of memory

Both node console and Qt5's V8-based QJSEngine can be crashed by the following code:
a = []; for (;;) { a.push("hello"); }
node's output before crash:
FATAL ERROR: JS Allocation failed - process out of memory
QJSEngine's output before crash:
#
# Fatal error in JS
# Allocation failed - process out of memory
#
If I run my QJSEngine test app (see below) under a debugger, it shows a v8::internal::OS::DebugBreak call inside V8 code. If I wrap the code calling QJSEngine::evaluate into __try-__except (SEH), then the app won't crash, but this solution is Windows-specific.
Question: Is there a way to handle v8::internal::OS::DebugBreak in a platform-independent way in node and Qt applications?
=== QJSEngine test code ===
Development environment: QtCreator with Qt5 and Windows SDK 7.1, on Windows XP SP3
QJSEngineTest.pro:
TEMPLATE = app
QT -= gui
QT += core qml
CONFIG -= app_bundle
CONFIG += console
SOURCES += main.cpp
TARGET = QJSEngineTest
main.cpp without SEH (this will crash):
#include <QtQml/QJSEngine>
int main(int, char**)
{
try {
QJSEngine engine;
QJSValue value = engine.evaluate("a = []; for (;;) { a.push('hello'); }");
qDebug(value.isError() ? "Error" : value.toString().toStdString().c_str());
} catch (...) {
qDebug("Exception");
}
return 0;
}
main.cpp with SEH (this won't crash, outputs "Fatal exception"):
#include <QtQml/QJSEngine>
#include <Windows.h>
void runTest()
{
try {
QJSEngine engine;
QJSValue value = engine.evaluate("a = []; for (;;) { a.push('hello'); }");
qDebug(value.isError() ? "Error" : value.toString().toStdString().c_str());
} catch (...) {
qDebug("Exception");
}
}
int main(int, char**)
{
__try {
runTest();
} __except(EXCEPTION_EXECUTE_HANDLER) {
qDebug("Fatal exception");
}
return 0;
}
I don't believe there's a cross-platform way to trap V8 fatal errors, but even if there were, or if there were some way to trap them on all the platforms you care about, I'm not sure what that would buy you.
The problem is that V8 uses a global flag that records whether a fatal error has occurred. Once that flag is set, V8 will reject any attempt to create new JavaScript contexts, so there's no point in continuing anyway. Try executing some benign JavaScript code after catching the initial fatal error. If I'm right, you'll get another fatal error right away.
In my opinion the right thing would be for Node and Qt to configure V8 to not raise fatal errors in the first place. Now that V8 supports isolates and memory constraints, process-killing fatal errors are no longer appropriate. Unfortunately it looks like V8's error handling code does not yet fully support those newer features, and still operates with the assumption that out-of-memory conditions are always unrecoverable.

Resources