Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Workspaces in Java 11 vs 8 #439

Closed
Immurb opened this issue Dec 11, 2018 · 5 comments
Closed

Bug: Workspaces in Java 11 vs 8 #439

Immurb opened this issue Dec 11, 2018 · 5 comments
Labels
Milestone

Comments

@Immurb
Copy link
Member

Immurb commented Dec 11, 2018

Workspaces created with JD+(Java 11) can't be opened with JD+(Java 8) and vice versa.

Error message:

java.io.IOException: Cannot probe workspace file format of 'WS_JavaX.xml'
	at ec.demetra.workspace.file.FileWorkspace.lambda$open$0(FileWorkspace.java:56)
	at java.base/java.util.Optional.orElseThrow(Optional.java:408)
	at ec.demetra.workspace.file.FileWorkspace.open(FileWorkspace.java:56)
[catch] at ec.nbdemetra.ws.FileRepository.load(FileRepository.java:194)...

The difference in the xml files seems to be the missing namespace in the Java 11 version. I attached my to test workspaces.
WS_Java8.zip
WS_Java11.zip

@charphi charphi added the bug label Dec 11, 2018
@charphi charphi added this to the 2.2.2 milestone Dec 11, 2018
@charphi
Copy link
Contributor

charphi commented Dec 11, 2018

Thanks for finding this huge bug !

@charphi
Copy link
Contributor

charphi commented Dec 11, 2018

Same problem with Java 9 and 10.

The problem seems to come from the use of XmlSchema annotation in package-info.java files. This annotation defines the namespaces of the resulting xml.
This annotation is not processed at runtime by JD+ if running under Java9+.

Note that it works fine outside JD+.

@charphi
Copy link
Contributor

charphi commented Dec 13, 2018

After some digging, I have found that the problem is not related to JAXB.
The problem is due to the failed loading of any package-info.class contained in a NetBeans module under Java9+.

NetBeans module provides its own class loader: org.netbeans.SandardModule.OneModuleClassLoader.
This class loader overrides some methods. Unfortunatly, Java9+ introduces a new method ClassLoader#loadClass(Module, String) that is not known by NetBeans module and is called in Package#getPackageInfo(). The result is that not package info is loaded at all.

// jdk11
private Class<?> getPackageInfo() {
  if (packageInfo == null) {
    // find package-info.class defined by loader
    String cn = packageName() + ".package-info";
    Module module = module();
    PrivilegedAction<ClassLoader> pa = module::getClassLoader;
    ClassLoader loader = AccessController.doPrivileged(pa);
    Class<?> c;
    if (loader != null) {
      c = loader.loadClass(module, cn);
    } else {
      c = BootLoader.loadClass(module, cn);
    }

    if (c != null) {
      packageInfo = c;
    } else {
      // store a proxy for the package info that has no annotations
      class PackageInfoProxy {}
      packageInfo = PackageInfoProxy.class;
    }
  }
  return packageInfo;
}
  
// jdk8
private Class<?> getPackageInfo() {
  if (packageInfo == null) {
    try {
      packageInfo = Class.forName(pkgName + ".package-info", false, loader);
    } catch (ClassNotFoundException ex) {
      // store a proxy for the package info that has no annotations
      class PackageInfoProxy {}
      packageInfo = PackageInfoProxy.class;
    }
  }
  return packageInfo;
}

@charphi
Copy link
Contributor

charphi commented Dec 14, 2018

It is possible to force load package-info by using Class.forName(String).

@charphi
Copy link
Contributor

charphi commented Dec 14, 2018

Fixed by b8ad2a2

@charphi charphi closed this as completed Dec 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants