2
votes

I have osgi project. Every bundle is a separate maven project. Project is large enough and includes about 10 bundles. Everything works and is ok.

Today I've added one more library - https://code.google.com/p/owasp-java-html-sanitizer/ . I've set all dependencies and ide (netbeans 8) shows everything is ok. However I get the following compilation code in this method:

@Override
public void sanitize(Map<String,Object> policies){
    PolicyFactory  policy=(PolicyFactory) policies.get("html0");
    this.code=policy.sanitize(this.code);
}

At the second line of the method (this.code...) I get the following compilation error: cannot access Function. Can't understand what it is about...
EDIT
Import section:

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.owasp.html.PolicyFactory;


EDIT

COMPILATION ERROR : 
-------------------------------------------------------------
com/subjects/SubjectDirItemCore.java:[166,24] error: cannot access Function
1 error
-------------------------------------------------------------
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 1.687s
Finished at: Wed Feb 18 16:11:11 MSK 2015
Final Memory: 14M/205M


EDIT
- I tried via mvn install -X

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project com.....: Compilation failure ..../subjects/SubjectDirItemCore.java:[166,24] error: cannot access Function

at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:537) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:196) at org.apache.maven.cli.MavenCli.main(MavenCli.java:141) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:409) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:352) Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure /..../subjects/SubjectDirItemCore.java:[166,24] error: cannot access Function

at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656) at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) ... 19 more [ERROR]

3
What JDK you use to compile your code? - mkrakhin
@mkrakhin openjdk version "1.8.0-internal" OpenJDK Runtime Environment (build 1.8.0-internal-_2014_11_22_23_46-b00) OpenJDK 64-Bit Server VM (build 25.40-b18, mixed mode) - user2022068
Ok. If you have guava in your pom.xml what is exact version of it? Also, what version of owasp-java-html-sanitizer you use? It looks like incompatibility issue between old guava and JDK8. Try to compile it against JDK7. - mkrakhin
@mkrakhin I don't have guava at THIS budle pom. Guava 12 is used only for owasp library. However at server side I have java8+gf4.1+ owasp lib bundle and it's ok. - user2022068
Try to add latest Guava (18) to your pom.xml. Guava 12 was released before JDK 8, and AFAIK it had some compatibility issues. - mkrakhin

3 Answers

1
votes

In my case this happened when the artifact was posted to the local Maven repository without a proper pom.xml so the transitive dependencies did not get downloaded. Look for the artifact where the unfound class is located and manually enter it in your pom.xml, that should fix the problem.

0
votes

This seems jar version issue. Most probably, newer version of jar containing class PolicyFactory has reduced visibility level of method sanitize. There must be new method which you are supposed to use as earlier method is restricted.

0
votes

I found the anwser - I used guava 12 instead of guava 11. I took 12 as it was the first version as osgi bundle.