Skip to content

Commit 3f76cff

Browse files
committed
[GR-27844] Handle illegal NewInstance.
PullRequest: graal/7772
2 parents 27c7f26 + 30411bd commit 3f76cff

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.graal.pointsto.constraints;
26+
27+
public class TypeInstantiationException extends UnsupportedFeatureException {
28+
29+
private static final long serialVersionUID = 8789851895801271717L;
30+
31+
public TypeInstantiationException(String message) {
32+
super(message);
33+
}
34+
}

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SharedGraphBuilderPhase.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.graalvm.compiler.phases.OptimisticOptimizations;
4040
import org.graalvm.compiler.word.WordTypes;
4141

42+
import com.oracle.graal.pointsto.constraints.TypeInstantiationException;
4243
import com.oracle.graal.pointsto.constraints.UnresolvedElementException;
4344
import com.oracle.svm.core.option.SubstrateOptionsParser;
4445
import com.oracle.svm.core.util.UserError;
@@ -155,6 +156,22 @@ protected JavaType maybeEagerlyResolve(JavaType type, ResolvedJavaType accessing
155156
}
156157
}
157158

159+
@Override
160+
protected void handleIllegalNewInstance(JavaType type) {
161+
/*
162+
* If --allow-incomplete-classpath is set defer the error reporting to runtime,
163+
* otherwise report the error during image building.
164+
*/
165+
if (allowIncompleteClassPath) {
166+
ExceptionSynthesizer.throwException(this, InstantiationError.class, type.toJavaName());
167+
} else {
168+
String message = "Cannot instantiate " + type.toJavaName() +
169+
". To diagnose the issue you can use the " + allowIncompleteClassPathOption() +
170+
" option. The instantiation error is then reported at run time.";
171+
throw new TypeInstantiationException(message);
172+
}
173+
}
174+
158175
@Override
159176
protected void handleUnresolvedNewInstance(JavaType type) {
160177
handleUnresolvedType(type);
@@ -255,12 +272,15 @@ private void handleUnresolvedMethod(JavaMethod javaMethod) {
255272

256273
private static void reportUnresolvedElement(String elementKind, String elementAsString) {
257274
String message = "Discovered unresolved " + elementKind + " during parsing: " + elementAsString +
258-
". To diagnose the issue you can use the " +
259-
SubstrateOptionsParser.commandArgument(NativeImageOptions.AllowIncompleteClasspath, "+") +
275+
". To diagnose the issue you can use the " + allowIncompleteClassPathOption() +
260276
" option. The missing " + elementKind + " is then reported at run time when it is accessed the first time.";
261277
throw new UnresolvedElementException(message);
262278
}
263279

280+
private static String allowIncompleteClassPathOption() {
281+
return SubstrateOptionsParser.commandArgument(NativeImageOptions.AllowIncompleteClasspath, "+");
282+
}
283+
264284
@Override
265285
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
266286
/* Not implemented in SVM (GR-4854) */

0 commit comments

Comments
 (0)