Java - compilation error: cannot access Function

13,929

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.

Share:
13,929
Admin
Author by

Admin

Updated on June 20, 2022

Comments

  • Admin
    Admin almost 2 years

    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]

  • Pranalee
    Pranalee about 9 years
    Check if you can get access to source code of class and see what is definition of PolicyFactory class and its methods. If not, just do ctrl+shift+T and search for PolicyFactory class. once .class file opens, you can do ctrl+O to check what all methods are exposed by this class and what are public methods.
  • Admin
    Admin about 9 years
    I've compiled that library from sources. And PolicyFactory has this method : public String sanitize(@Nullable String html) { return sanitize(html, null, null); }
  • Pranalee
    Pranalee about 9 years
    have you made sure that there are no multiple versions of jar? I can't think of any other reason if method is public.
  • Admin
    Admin about 9 years
    Yes, this lib is not osgi bundle, so I created my maven osgi project and build osgi bundle. And this new bundle is added to dependencies.