Skip to content

Commit 83cb0d4

Browse files
authored
Merge pull request #328 from google/suppress-sun-memory-warnings
Suppress Sun unsafe memory warnings on JDK 24
2 parents a534287 + 0a8b3b8 commit 83cb0d4

File tree

3 files changed

+53
-35
lines changed

3 files changed

+53
-35
lines changed

packages/google-closure-compiler/lib/node/index.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const javaPath = 'java';
3030

3131
export default class Compiler {
3232
/**
33-
* @param {Object<string,string>|Array<string>} args
33+
* @param {Object<string,string|boolean>|Array<string>} args
3434
* @param {Array<String>=} extraCommandArgs
3535
*/
3636
constructor(args, extraCommandArgs) {
@@ -42,15 +42,11 @@ export default class Compiler {
4242
if (Array.isArray(args)) {
4343
this.commandArguments.push(...args);
4444
} else {
45-
for (let key in args) {
46-
if (Array.isArray(args[key])) {
47-
for (let i = 0; i < args[key].length; i++) {
48-
this.commandArguments.push(
49-
this.formatArgument(key, args[key][i]));
50-
}
45+
for (const [key, val] of Object.entries(args)) {
46+
if (Array.isArray(val)) {
47+
this.commandArguments.push(...val.map((item) => this.formatArgument(key, item)));
5148
} else {
52-
this.commandArguments.push(
53-
this.formatArgument(key, args[key]));
49+
this.commandArguments.push(this.formatArgument(key, val));
5450
}
5551
}
5652
}
@@ -65,7 +61,12 @@ export default class Compiler {
6561
/** @param {function(number, string, string)=} callback */
6662
run(callback) {
6763
if (this.JAR_PATH) {
68-
this.commandArguments.unshift('-jar', this.JAR_PATH);
64+
this.commandArguments.unshift(
65+
'-XX:+IgnoreUnrecognizedVMOptions',
66+
'--sun-misc-unsafe-memory-access=allow',
67+
'-jar',
68+
this.JAR_PATH,
69+
);
6970
if (this.extraCommandArgs) {
7071
this.commandArguments.unshift(...this.extraCommandArgs);
7172
}

packages/google-closure-compiler/test/node.js

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,21 @@ describe('closure-compiler node bindings', () => {
3939

4040
describe('java version', () => {
4141
let originalTimeout;
42+
const baseCompilerArgs = [
43+
'--one=true',
44+
'--two=two',
45+
'--three=one',
46+
'--three=two',
47+
'--three=three',
48+
];
49+
const expandedCompilerArgs = [
50+
'-XX:+IgnoreUnrecognizedVMOptions',
51+
'--sun-misc-unsafe-memory-access=allow',
52+
'-jar',
53+
JAR_PATH,
54+
].concat(baseCompilerArgs);
55+
const extraCompilerArgs = ['-Xms2048m'];
56+
const expandedPlusExtraArgs = extraCompilerArgs.concat(expandedCompilerArgs);
4257
beforeEach(() => {
4358
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
4459
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
@@ -65,57 +80,51 @@ describe('closure-compiler node bindings', () => {
6580
expect(hasRun).toBe(true);
6681
});
6782

68-
it('should normalize an options object to an arguments array', () => {
83+
it('should normalize an options object to an arguments array immediately', () => {
6984
const compiler = new Compiler({
7085
one: true,
7186
two: 'two',
7287
three: ['one', 'two', 'three']
7388
});
7489

75-
const expectedArray = ['--one=true', '--two=two',
76-
'--three=one', '--three=two', '--three=three'];
77-
expect(compiler.commandArguments.length).toBe(expectedArray.length);
90+
expect(compiler.commandArguments.length).toBe(baseCompilerArgs.length);
7891
compiler.commandArguments.forEach((item, index) => {
79-
expect(expectedArray[index]).toBe(item);
92+
expect(baseCompilerArgs[index]).toBe(item);
8093
});
8194
});
8295

8396
it('should prepend the -jar argument and compiler path when configured by array', async () => {
84-
const expectedArray = ['-jar', JAR_PATH, '--one=true', '--two=two',
85-
'--three=one', '--three=two', '--three=three'];
86-
87-
const compiler = new Compiler(expectedArray.slice(2));
97+
const compiler = new Compiler(baseCompilerArgs);
8898
await new Promise((resolve) => compiler.run(resolve));
8999

90-
expect(compiler.commandArguments.length).toBe(expectedArray.length);
100+
expect(compiler.commandArguments.length).toBe(expandedCompilerArgs.length);
91101
compiler.commandArguments.forEach((item, index) => {
92-
expect(expectedArray[index]).toBe(item);
102+
expect(expandedCompilerArgs[index]).toBe(item);
93103
});
94104
});
95105

96106
describe('extra command arguments', () => {
97107
it('should include initial command arguments when configured by an options object', async () => {
98-
const expectedArray = ['-Xms2048m', '-jar', JAR_PATH, '--one=true', '--two=two',
99-
'--three=one', '--three=two', '--three=three'];
100-
101-
const compiler = new Compiler(expectedArray.slice(3), expectedArray.slice(0, 1));
108+
const args = {
109+
one: true,
110+
two: 'two',
111+
three: ['one', 'two', 'three'],
112+
};
113+
const compiler = new Compiler(args, extraCompilerArgs);
102114
await new Promise((resolve) => compiler.run(resolve));
103115

104-
expect(compiler.commandArguments.length).toBe(expectedArray.length);
116+
expect(compiler.commandArguments.length).toBe(expandedPlusExtraArgs.length);
105117
compiler.commandArguments.forEach(function (item, index) {
106-
expect(expectedArray[index]).toBe(item);
118+
expect(expandedPlusExtraArgs[index]).toBe(item);
107119
});
108120
});
109121

110122
it('should include initial command arguments when configured by array', async () => {
111-
const expectedArray = ['-Xms2048m', '-jar', JAR_PATH, '--one=true', '--two=two',
112-
'--three=one', '--three=two', '--three=three'];
113-
114-
const compiler = new Compiler(expectedArray.slice(3), expectedArray.slice(0, 1));
123+
const compiler = new Compiler(baseCompilerArgs, extraCompilerArgs);
115124
await new Promise((resolve) => compiler.run(resolve));
116-
expect(compiler.commandArguments.length).toBe(expectedArray.length);
125+
expect(compiler.commandArguments.length).toBe(expandedPlusExtraArgs.length);
117126
compiler.commandArguments.forEach(function (item, index) {
118-
expect(expectedArray[index]).toBe(item);
127+
expect(expandedPlusExtraArgs[index]).toBe(item);
119128
});
120129
});
121130
});

test/compiler.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ process.on('unhandledRejection', (e) => { throw e; });
3737
describe('compiler.jar', function () {
3838
it('should not be a snapshot build', async () => {
3939
const compiler = new Compiler({version: true});
40-
const {stdout} = await new Promise((resolve) =>
40+
const {exitCode, stdout, stderr} = await new Promise((resolve) =>
4141
compiler.run((exitCode, stdout, stderr) =>
4242
resolve({
4343
exitCode,
@@ -46,6 +46,10 @@ describe('compiler.jar', function () {
4646
})
4747
)
4848
);
49+
if (exitCode !== 0 || stderr) {
50+
console.error(`${stdout || ''}${stderr || ''}`);
51+
}
52+
expect(exitCode).toBe(0);
4953
let versionInfo = (stdout || '').match(compilerVersionMatch);
5054
expect(versionInfo).not.toBeNullish();
5155
versionInfo = versionInfo || [];
@@ -56,7 +60,7 @@ describe('compiler.jar', function () {
5660
it('version should be equal to the package major version', async () => {
5761
const compiler = new Compiler({version: true});
5862
const packageVer = new Semver(packageInfo.version);
59-
const {stdout} = await new Promise((resolve) =>
63+
const {exitCode, stdout, stderr} = await new Promise((resolve) =>
6064
compiler.run((exitCode, stdout, stderr) =>
6165
resolve({
6266
exitCode,
@@ -65,6 +69,10 @@ describe('compiler.jar', function () {
6569
})
6670
)
6771
);
72+
if (exitCode !== 0 || stderr) {
73+
console.error(`${stdout || ''}${stderr || ''}`);
74+
}
75+
expect(exitCode).toBe(0);
6876
let versionInfo = (stdout || '').match(compilerVersionMatch);
6977
expect(versionInfo).not.toBeNullish();
7078
versionInfo = versionInfo || [];

0 commit comments

Comments
 (0)