JDK-8044695 : __stack__ becomes visible in Error properties
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-06-03
  • Updated: 2014-07-29
  • Resolved: 2014-06-04
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8 JDK 9
8u20Fixed 9 b17Fixed
Description
the __stack__ property becomes visible after accessing Error.stack -

var err = new Error("the-message");
print('err.json1: '+JSON.stringify(err));
print('err: '+err);
print('err.message: '+err.message);
print('err.stack: '+err.stack);
print('err.json2: '+JSON.stringify(err));

this prints -

err.json1: {}
err: Error: the-message
err.message: the-message
err.stack: Error: the-message
	at <program> (error.js:1)
err.json2: {"__stack__":"Error: the-message\n\tat <program> (error.js:1)"}

node/v8 prints -

err.json1: {}
err: Error: the-message
err.message: the-message
err.stack: Error: the-message
    ...
    at node.js:902:3
err.json2: {}

Comments
Like other "internal" properties like __lineNumber__, __columnNumber__ etc., __stack__ should also be made non-enumerable, own property. That will make it non-visible to APIs like JSON.stringify (and other APIs that use enumerable properties)
04-06-2014