Skip to content

Commit

Permalink
Handle illegal NewInstance.
Browse files Browse the repository at this point in the history
  • Loading branch information
cstancu committed Dec 1, 2020
1 parent 8fc423e commit 30411bd
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2020, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package com.oracle.graal.pointsto.constraints;

public class TypeInstantiationException extends UnsupportedFeatureException {

private static final long serialVersionUID = 8789851895801271717L;

public TypeInstantiationException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.graalvm.compiler.phases.OptimisticOptimizations;
import org.graalvm.compiler.word.WordTypes;

import com.oracle.graal.pointsto.constraints.TypeInstantiationException;
import com.oracle.graal.pointsto.constraints.UnresolvedElementException;
import com.oracle.svm.core.option.SubstrateOptionsParser;
import com.oracle.svm.core.util.UserError;
Expand Down Expand Up @@ -155,6 +156,22 @@ protected JavaType maybeEagerlyResolve(JavaType type, ResolvedJavaType accessing
}
}

@Override
protected void handleIllegalNewInstance(JavaType type) {
/*
* If --allow-incomplete-classpath is set defer the error reporting to runtime,
* otherwise report the error during image building.
*/
if (allowIncompleteClassPath) {
ExceptionSynthesizer.throwException(this, InstantiationError.class, type.toJavaName());
} else {
String message = "Cannot instantiate " + type.toJavaName() +
". To diagnose the issue you can use the " + allowIncompleteClassPathOption() +
" option. The instantiation error is then reported at run time.";
throw new TypeInstantiationException(message);
}
}

@Override
protected void handleUnresolvedNewInstance(JavaType type) {
handleUnresolvedType(type);
Expand Down Expand Up @@ -255,12 +272,15 @@ private void handleUnresolvedMethod(JavaMethod javaMethod) {

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

private static String allowIncompleteClassPathOption() {
return SubstrateOptionsParser.commandArgument(NativeImageOptions.AllowIncompleteClasspath, "+");
}

@Override
protected void emitCheckForInvokeSuperSpecial(ValueNode[] args) {
/* Not implemented in SVM (GR-4854) */
Expand Down

0 comments on commit 30411bd

Please sign in to comment.