mirror of
https://github.com/i-net-software/JWebAssembly.git
synced 2025-03-14 18:43:27 +01:00
Fix a NPE/better error message if class is missing
This commit is contained in:
parent
b37924ce5b
commit
42598a3634
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2020 - 2022 Volker Berlin (i-net software)
|
||||
Copyright 2020 - 2023 Volker Berlin (i-net software)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -24,6 +24,7 @@ import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import de.inetsoftware.classparser.ClassFile;
|
||||
import de.inetsoftware.jwebassembly.WasmException;
|
||||
|
||||
/**
|
||||
* Cache and manager for the loaded ClassFiles
|
||||
@ -87,6 +88,26 @@ public class ClassFileLoader {
|
||||
return classFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the ClassFile from cache or load it. This returns ever a ClassFile or throw an exception if not found.
|
||||
*
|
||||
* @param className
|
||||
* the class name like "java/lang/Object"
|
||||
* @return the ClassFile or null
|
||||
* @throws IOException
|
||||
* If any I/O error occur
|
||||
* @throws WasmException
|
||||
* if the class was not found
|
||||
*/
|
||||
@Nonnull
|
||||
public ClassFile getClassFile( String className ) throws IOException, WasmException {
|
||||
ClassFile classFile = get( className );
|
||||
if( classFile != null ) {
|
||||
return classFile;
|
||||
}
|
||||
throw new WasmException( "Missing class: " + className, -1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a class file to the weak cache.
|
||||
*
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 - 2022 Volker Berlin (i-net software)
|
||||
Copyright 2018 - 2023 Volker Berlin (i-net software)
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
@ -871,7 +871,7 @@ public class TypeManager {
|
||||
|
||||
// list classes of the hierarchy and its interfaces
|
||||
Set<String> interfaceNames = new LinkedHashSet<>();
|
||||
for( ClassFile classFile = classFileLoader.get( name );; ) {
|
||||
for( ClassFile classFile = classFileLoader.getClassFile( name );; ) {
|
||||
classFiles.add( classFile );
|
||||
listInterfaceTypes( classFile, types, classFileLoader, interfaceTypes, interfaceNames );
|
||||
|
||||
@ -879,7 +879,7 @@ public class TypeManager {
|
||||
if( superClass == null ) {
|
||||
break;
|
||||
}
|
||||
classFile = classFileLoader.get( superClass.getName() );
|
||||
classFile = classFileLoader.getClassFile( superClass.getName() );
|
||||
}
|
||||
|
||||
// if the top most class abstract then there can be no instance. A itable we need only for an instance
|
||||
@ -890,7 +890,7 @@ public class TypeManager {
|
||||
// create the itables for all interfaces of this type
|
||||
for( StructType type : interfaceTypes ) {
|
||||
String interName = type.name;
|
||||
ClassFile interClassFile = classFileLoader.get( interName );
|
||||
ClassFile interClassFile = classFileLoader.getClassFile( interName );
|
||||
List<FunctionName> iMethods = null;
|
||||
|
||||
for( MethodInfo interMethod : interClassFile.getMethods() ) {
|
||||
@ -907,7 +907,7 @@ public class TypeManager {
|
||||
if( method == null ) {
|
||||
// search if there is a default implementation in an interface
|
||||
for( String iClassName : interfaceNames ) {
|
||||
ClassFile iClassFile = classFileLoader.get( iClassName );
|
||||
ClassFile iClassFile = classFileLoader.getClassFile( iClassName );
|
||||
method = iClassFile.getMethod( iName.methodName, iName.signature );
|
||||
if( method != null ) {
|
||||
break;
|
||||
|
Loading…
x
Reference in New Issue
Block a user