StrictMode shows 10 errors for one line of code
I am running StrictMode.enableDefaults()
to clean up my code and I have one line of code that sets the ZoneId
that gives 10 StrictMode
violations at about 195ms each for the single line of code. The Log.d
statement just above the line only shows once in Logcat. I get the same errors if I use ZoneId.of(tz.getID())
.
What's going on here? I checked the ZoneId
source and the cause was not obvious to me. Is this from ZoneId
parsing the input? Log times only go from 16:46:09.079 to 16:46:09.080, but otherwise the 10 stack traces look the same.
Am I truly loosing about 195ms x 10 or is this some sort of bug? Thanks
Routine that has the error:
if (lastUpdateZoneOffset.equals(utcOffset)) {
// last update offset is zero, so add back time from observation station time zone
Log.d(TAG, "tz.getID()");
//ZoneId observationStationZoneId = ZoneId.of(tz.getID());
ZoneId observationStationZoneId = ZoneId.of("America/Denver"); **<---Error Here**
ZonedDateTime zdt = offsetDateTime.atZoneSameInstant(observationStationZoneId);
// format to 14 Apr 4:16 PM Note: the "a" pattern only allows upper case for AM/PM
lastUpdate = zdt.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
} else {
lastUpdate = offsetDateTime.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
}
Typical stack trace:
01-01 16:46:09.079 24614-24614 D/StrictMode: StrictMode policy violation; ~duration=196 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:117)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:158)
at java.util.zip.ZipFile.<init>(ZipFile.java:119)
at dalvik.system.DexPathList$Element.maybeInit(DexPathList.java:431)
at dalvik.system.DexPathList$Element.findResource(DexPathList.java:445)
at dalvik.system.DexPathList.findResources(DexPathList.java:361)
at dalvik.system.BaseDexClassLoader.findResources(BaseDexClassLoader.java:72)
at java.lang.ClassLoader.getResources(ClassLoader.java:425)
at java.util.ServiceLoader.internalLoad(ServiceLoader.java:129)
at java.util.ServiceLoader.reload(ServiceLoader.java:93)
at java.util.ServiceLoader.<init>(ServiceLoader.java:86)
at java.util.ServiceLoader.load(ServiceLoader.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer$ServiceLoaderZoneRulesInitializer.initializeProviders(ZoneRulesInitializer.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer.initialize(ZoneRulesInitializer.java:89)
at org.threeten.bp.zone.ZoneRulesProvider.<clinit>(ZoneRulesProvider.java:82)
at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:121)
at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
at org.threeten.bp.ZoneId.of(ZoneId.java:358)
at com.drme.weatherNoaa.CurrentConditionsFragment.getDisplayLastUpdate(CurrentConditionsFragment.java:674)
at com.drme.weatherNoaa.CurrentConditionsFragment.updateCurrentConditionsUi(CurrentConditionsFragment.java:543)
at com.drme.weatherNoaa.DataManager$1.handleMessage(DataManager.java:201)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

add a comment |
I am running StrictMode.enableDefaults()
to clean up my code and I have one line of code that sets the ZoneId
that gives 10 StrictMode
violations at about 195ms each for the single line of code. The Log.d
statement just above the line only shows once in Logcat. I get the same errors if I use ZoneId.of(tz.getID())
.
What's going on here? I checked the ZoneId
source and the cause was not obvious to me. Is this from ZoneId
parsing the input? Log times only go from 16:46:09.079 to 16:46:09.080, but otherwise the 10 stack traces look the same.
Am I truly loosing about 195ms x 10 or is this some sort of bug? Thanks
Routine that has the error:
if (lastUpdateZoneOffset.equals(utcOffset)) {
// last update offset is zero, so add back time from observation station time zone
Log.d(TAG, "tz.getID()");
//ZoneId observationStationZoneId = ZoneId.of(tz.getID());
ZoneId observationStationZoneId = ZoneId.of("America/Denver"); **<---Error Here**
ZonedDateTime zdt = offsetDateTime.atZoneSameInstant(observationStationZoneId);
// format to 14 Apr 4:16 PM Note: the "a" pattern only allows upper case for AM/PM
lastUpdate = zdt.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
} else {
lastUpdate = offsetDateTime.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
}
Typical stack trace:
01-01 16:46:09.079 24614-24614 D/StrictMode: StrictMode policy violation; ~duration=196 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:117)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:158)
at java.util.zip.ZipFile.<init>(ZipFile.java:119)
at dalvik.system.DexPathList$Element.maybeInit(DexPathList.java:431)
at dalvik.system.DexPathList$Element.findResource(DexPathList.java:445)
at dalvik.system.DexPathList.findResources(DexPathList.java:361)
at dalvik.system.BaseDexClassLoader.findResources(BaseDexClassLoader.java:72)
at java.lang.ClassLoader.getResources(ClassLoader.java:425)
at java.util.ServiceLoader.internalLoad(ServiceLoader.java:129)
at java.util.ServiceLoader.reload(ServiceLoader.java:93)
at java.util.ServiceLoader.<init>(ServiceLoader.java:86)
at java.util.ServiceLoader.load(ServiceLoader.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer$ServiceLoaderZoneRulesInitializer.initializeProviders(ZoneRulesInitializer.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer.initialize(ZoneRulesInitializer.java:89)
at org.threeten.bp.zone.ZoneRulesProvider.<clinit>(ZoneRulesProvider.java:82)
at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:121)
at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
at org.threeten.bp.ZoneId.of(ZoneId.java:358)
at com.drme.weatherNoaa.CurrentConditionsFragment.getDisplayLastUpdate(CurrentConditionsFragment.java:674)
at com.drme.weatherNoaa.CurrentConditionsFragment.updateCurrentConditionsUi(CurrentConditionsFragment.java:543)
at com.drme.weatherNoaa.DataManager$1.handleMessage(DataManager.java:201)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

2
This post describes strict mode in detail: "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
– Robert Harvey♦
Jan 2 at 0:40
add a comment |
I am running StrictMode.enableDefaults()
to clean up my code and I have one line of code that sets the ZoneId
that gives 10 StrictMode
violations at about 195ms each for the single line of code. The Log.d
statement just above the line only shows once in Logcat. I get the same errors if I use ZoneId.of(tz.getID())
.
What's going on here? I checked the ZoneId
source and the cause was not obvious to me. Is this from ZoneId
parsing the input? Log times only go from 16:46:09.079 to 16:46:09.080, but otherwise the 10 stack traces look the same.
Am I truly loosing about 195ms x 10 or is this some sort of bug? Thanks
Routine that has the error:
if (lastUpdateZoneOffset.equals(utcOffset)) {
// last update offset is zero, so add back time from observation station time zone
Log.d(TAG, "tz.getID()");
//ZoneId observationStationZoneId = ZoneId.of(tz.getID());
ZoneId observationStationZoneId = ZoneId.of("America/Denver"); **<---Error Here**
ZonedDateTime zdt = offsetDateTime.atZoneSameInstant(observationStationZoneId);
// format to 14 Apr 4:16 PM Note: the "a" pattern only allows upper case for AM/PM
lastUpdate = zdt.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
} else {
lastUpdate = offsetDateTime.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
}
Typical stack trace:
01-01 16:46:09.079 24614-24614 D/StrictMode: StrictMode policy violation; ~duration=196 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:117)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:158)
at java.util.zip.ZipFile.<init>(ZipFile.java:119)
at dalvik.system.DexPathList$Element.maybeInit(DexPathList.java:431)
at dalvik.system.DexPathList$Element.findResource(DexPathList.java:445)
at dalvik.system.DexPathList.findResources(DexPathList.java:361)
at dalvik.system.BaseDexClassLoader.findResources(BaseDexClassLoader.java:72)
at java.lang.ClassLoader.getResources(ClassLoader.java:425)
at java.util.ServiceLoader.internalLoad(ServiceLoader.java:129)
at java.util.ServiceLoader.reload(ServiceLoader.java:93)
at java.util.ServiceLoader.<init>(ServiceLoader.java:86)
at java.util.ServiceLoader.load(ServiceLoader.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer$ServiceLoaderZoneRulesInitializer.initializeProviders(ZoneRulesInitializer.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer.initialize(ZoneRulesInitializer.java:89)
at org.threeten.bp.zone.ZoneRulesProvider.<clinit>(ZoneRulesProvider.java:82)
at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:121)
at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
at org.threeten.bp.ZoneId.of(ZoneId.java:358)
at com.drme.weatherNoaa.CurrentConditionsFragment.getDisplayLastUpdate(CurrentConditionsFragment.java:674)
at com.drme.weatherNoaa.CurrentConditionsFragment.updateCurrentConditionsUi(CurrentConditionsFragment.java:543)
at com.drme.weatherNoaa.DataManager$1.handleMessage(DataManager.java:201)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

I am running StrictMode.enableDefaults()
to clean up my code and I have one line of code that sets the ZoneId
that gives 10 StrictMode
violations at about 195ms each for the single line of code. The Log.d
statement just above the line only shows once in Logcat. I get the same errors if I use ZoneId.of(tz.getID())
.
What's going on here? I checked the ZoneId
source and the cause was not obvious to me. Is this from ZoneId
parsing the input? Log times only go from 16:46:09.079 to 16:46:09.080, but otherwise the 10 stack traces look the same.
Am I truly loosing about 195ms x 10 or is this some sort of bug? Thanks
Routine that has the error:
if (lastUpdateZoneOffset.equals(utcOffset)) {
// last update offset is zero, so add back time from observation station time zone
Log.d(TAG, "tz.getID()");
//ZoneId observationStationZoneId = ZoneId.of(tz.getID());
ZoneId observationStationZoneId = ZoneId.of("America/Denver"); **<---Error Here**
ZonedDateTime zdt = offsetDateTime.atZoneSameInstant(observationStationZoneId);
// format to 14 Apr 4:16 PM Note: the "a" pattern only allows upper case for AM/PM
lastUpdate = zdt.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
} else {
lastUpdate = offsetDateTime.format(DateTimeFormatter.ofPattern("dd MMM h:mm a"));
lastUpdate += " " + tz.getDisplayName(true, SHORT);
}
Typical stack trace:
01-01 16:46:09.079 24614-24614 D/StrictMode: StrictMode policy violation; ~duration=196 ms: android.os.StrictMode$StrictModeDiskReadViolation: policy=31 violation=2
at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1137)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:182)
at libcore.io.IoBridge.open(IoBridge.java:442)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:117)
at java.io.RandomAccessFile.<init>(RandomAccessFile.java:149)
at java.util.zip.ZipFile.<init>(ZipFile.java:158)
at java.util.zip.ZipFile.<init>(ZipFile.java:119)
at dalvik.system.DexPathList$Element.maybeInit(DexPathList.java:431)
at dalvik.system.DexPathList$Element.findResource(DexPathList.java:445)
at dalvik.system.DexPathList.findResources(DexPathList.java:361)
at dalvik.system.BaseDexClassLoader.findResources(BaseDexClassLoader.java:72)
at java.lang.ClassLoader.getResources(ClassLoader.java:425)
at java.util.ServiceLoader.internalLoad(ServiceLoader.java:129)
at java.util.ServiceLoader.reload(ServiceLoader.java:93)
at java.util.ServiceLoader.<init>(ServiceLoader.java:86)
at java.util.ServiceLoader.load(ServiceLoader.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer$ServiceLoaderZoneRulesInitializer.initializeProviders(ZoneRulesInitializer.java:122)
at org.threeten.bp.zone.ZoneRulesInitializer.initialize(ZoneRulesInitializer.java:89)
at org.threeten.bp.zone.ZoneRulesProvider.<clinit>(ZoneRulesProvider.java:82)
at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:121)
at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
at org.threeten.bp.ZoneId.of(ZoneId.java:358)
at com.drme.weatherNoaa.CurrentConditionsFragment.getDisplayLastUpdate(CurrentConditionsFragment.java:674)
at com.drme.weatherNoaa.CurrentConditionsFragment.updateCurrentConditionsUi(CurrentConditionsFragment.java:543)
at com.drme.weatherNoaa.DataManager$1.handleMessage(DataManager.java:201)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)


edited Jan 2 at 2:51


shizhen
3,78541335
3,78541335
asked Jan 2 at 0:36
mtdavemmtdavem
64210
64210
2
This post describes strict mode in detail: "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
– Robert Harvey♦
Jan 2 at 0:40
add a comment |
2
This post describes strict mode in detail: "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
– Robert Harvey♦
Jan 2 at 0:40
2
2
This post describes strict mode in detail: "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
– Robert Harvey♦
Jan 2 at 0:40
This post describes strict mode in detail: "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
– Robert Harvey♦
Jan 2 at 0:40
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000055%2fstrictmode-shows-10-errors-for-one-line-of-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54000055%2fstrictmode-shows-10-errors-for-one-line-of-code%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
This post describes strict mode in detail: "StrictMode is most commonly used to catch accidental disk or network access on the application's main thread, where UI operations are received and animations take place. Keeping disk and network operations off the main thread makes for much smoother, more responsive applications. By keeping your application's main thread responsive, you also prevent ANR dialogs from being shown to users."
– Robert Harvey♦
Jan 2 at 0:40