Class file from PsiJavaFile with IntelliJ 2019.1



Before IntelliJ 2019.1, I used to fetch Java class files like this:

public static FileInfos getClassFileForJavaFile(PsiJavaFile javaFile, String packageName) throws PatchPluginException {
PsiClass[] psiClassFiles = javaFile.getClasses();
List<CompilerPathsEx.ClassFileDescriptor> classFiles = new ArrayList<>();
for (PsiClass psiClass : psiClassFiles) {

if (classFiles.get(0) == null) {
throw new PatchPluginException("No class file found. Please rebuild all necessary modules and make sure to have the classes in the target folders");

return new FileInfos(packageName, classFiles);

This is no longer working with IntelliJ 2019.1s JDK.
Is there another solution?


P.S. See also

1 comment

Hi Stefan,

that code was created for Bytecode Viewer plugin and was later moved into it. At the moment of change, there were no detectable usages of that code by plugins (probably yours is in-house and not published to the repository).

There is no similar method in the current API. I'd suggest to copy relevant parts from ByteCodeViewerManager#loadClassFileBytes (AFAIU, you only need the "source code" branch of it).


Please sign in to leave a comment.