Index: contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java =================================================================== --- contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java (revision 937263) +++ contrib/queries/src/java/org/apache/lucene/search/regex/JakartaRegexpCapabilities.java (working copy) @@ -18,7 +18,9 @@ */ import org.apache.regexp.RE; -import org.apache.regexp.RegexpTunnel; +import org.apache.regexp.REProgram; +import java.lang.reflect.Field; +import java.lang.reflect.Method; /** * Implementation tying Jakarta @@ -29,6 +31,22 @@ */ public class JakartaRegexpCapabilities implements RegexCapabilities { private RE regexp; + + private static Field prefixField; + private static Method getPrefixMethod; + static { + try { + getPrefixMethod = REProgram.class.getMethod("getPrefix"); + } catch (Exception e) { + getPrefixMethod = null; + } + try { + prefixField = REProgram.class.getDeclaredField("prefix"); + prefixField.setAccessible(true); + } catch (Exception e) { + prefixField = null; + } + } // Define the flags that are possible. Redefine them here // to avoid exposing the RE class to the caller. @@ -70,8 +88,20 @@ } public String prefix() { - char[] prefix = RegexpTunnel.getPrefix(regexp); - return prefix == null ? null : new String(prefix); + try { + final char[] prefix; + if (getPrefixMethod != null) { + prefix = (char[]) getPrefixMethod.invoke(regexp.getProgram()); + } else if (prefixField != null) { + prefix = (char[]) prefixField.get(regexp.getProgram()); + } else { + return null; + } + return prefix == null ? null : new String(prefix); + } catch (Exception e) { + // if we cannot get the prefix, return none + return null; + } } @Override Index: contrib/queries/src/java/org/apache/regexp/package.html =================================================================== --- contrib/queries/src/java/org/apache/regexp/package.html (revision 937263) +++ contrib/queries/src/java/org/apache/regexp/package.html (working copy) @@ -1,24 +0,0 @@ - - - - -This package exists to allow access to useful package protected data within -Jakarta Regexp. This data has now been opened up with an accessor, but -an official release with that change has not been made to date. - - Index: contrib/queries/src/java/org/apache/regexp/RegexpTunnel.java =================================================================== --- contrib/queries/src/java/org/apache/regexp/RegexpTunnel.java (revision 937263) +++ contrib/queries/src/java/org/apache/regexp/RegexpTunnel.java (working copy) @@ -1,29 +0,0 @@ -package org.apache.regexp; - -/** - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -/** - * This class exists as a gateway to access useful Jakarta Regexp package protected data. - */ -public class RegexpTunnel { - public static char[] getPrefix(RE regexp) { - REProgram program = regexp.getProgram(); - return program.prefix; - } -}