question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Null reference fails to decompile

See original GitHub issue

Compiling and decompiling this simple code leads to a NPE. (version 0.149)

public enum CrashEnum {
	SAMPLE;

	public CrashEnum[] cloneValues() {
		return ((CrashEnum[]) null).clone();
	}
}

CrashEnum.class.txt

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
GraxCodecommented, Apr 26, 2020

Conversion.toBytecode0(dummy) produces an empty class file in bytes. But it doesn’t matter, as it is not the cause of the problem. Here’s how to reproduce the NPE:

	public static void main(String... args) {
		CfrDriver driver = new CfrDriver.Builder().withClassFileSource(new DataSource()).build();
		driver.analyse(Arrays.asList("CrashEnum.class"));
	}

	public static class DataSource implements ClassFileSource {
		@Override
		public void informAnalysisRelativePathDetail(String usePath, String classFilePath) {
		}

		@Override
		public Collection<String> addJar(String jarPath) {
			throw new UnsupportedOperationException();
		}

		@Override
		public String getPossiblyRenamedPath(String path) {
			return path;
		}

		@Override
		public Pair<byte[], String> getClassFileContent(String path) throws IOException {
			if (!path.equals("CrashEnum.class"))
				throw new FileNotFoundException("Can't find " + path);
			return Pair.make(Files.readAllBytes(new File("CrashEnum.class").toPath()), "CrashEnum.class");
		}
	}

Don’t forget to place the class file in the same directory!

0reactions
GraxCodecommented, Apr 27, 2020

I now remember why i used a dummy class instead of just throwing an FNF exception. CFR creates very long comments at the top of the decompiled class file like

Could not load the following classes: 
XXX
YYY
ZZZ

They are pretty annoying on huge class files, and I’m not sure if there is a way to disable them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error decompiling method. System.NullReferenceException ...
Steps to reproduce Open the assembly Rewired_Core.zip in ILSpy Try and decompile the class Rewired.Data.UserData Error message shown Error ...
Read more >
Decompiled Sources only show "throw null" for every .NET ...
For me, every class is like this. If I'm looking in the wrong location (the reference), how can I make Visual studio look...
Read more >
Decompile source to symbol file fails
Hi Team, I am encountering the below error when I try 'Decompile Source to Symbol File' (from Modules window) for the code deployed...
Read more >
Decompile .NET code while debugging - Visual Studio ...
This is due to a sequence point null-reference error in ILSpy. We have mitigated the failure by catching these issues and gracefully failing...
Read more >
How to handle null reference exception in my code?
Simply execute it under debugger, it will stop the execution where the exception is thrown. Put a break point on that line, restart...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found